package com.qianhui.action;

import com.qianhui.bean.MathExtend;
import com.qianhui.bean.Page;
import com.qianhui.common.*;
import com.qianhui.dao.OrderGoodsDAO;
import com.qianhui.orderapi.ODAPI;
import com.qianhui.pojo.*;
import com.qianhui.view.*;
import org.apache.struts2.ServletActionContext;
import org.json.JSONException;
import org.json.JSONObject;
import weixin.popular.api.MessageAPI;
import weixin.popular.api.QrcodeAPI;
import weixin.popular.api.SnsAPI;
import weixin.popular.api.UserAPI;
import weixin.popular.bean.BaseResult;
import weixin.popular.bean.message.message.TextMessage;
import weixin.popular.bean.paymch.MchBaseResult;
import weixin.popular.bean.paymch.MchPayNotify;
import weixin.popular.bean.qrcode.QrcodeTicket;
import weixin.popular.bean.sns.SnsToken;
import weixin.popular.bean.user.User;
import weixin.popular.support.TicketManager;
import weixin.popular.support.TokenManager;
import weixin.popular.util.SignatureUtil;
import weixin.popular.util.XMLConverUtil;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;

public class BuyerAction extends BaseAction
{
    // 常用变量
    private Map<String, Object> json;// 返回到前台的map对象

    private String goodsTypeJson;

    private Page page;
    private int rowSize;
    private Goods goods;

    private String commonStr;

    private boolean canSubmitOrder;
    private String message;
    private BigDecimal allTotalPrice;// 商品总价格
    private boolean goodsIsCollected;

    private BuyerAddress buyerAddress;
    private List<BuyerAddress> buyerAddressList;
    private String buyerPeopleId;
    private String buyerRealName;
    private List<Order> orderList;
    private List<ComplexOrder> complexOrderList;
    private List<GoodsTypeViewAndList> viewAndList;
    private Map<String, List<Goods>> goodsTypeAndGoodsListMap;
    private ComplexOrder complexOrder;
    private BuyerCollection buyerCollection;
    private List<CollectionView> collectionViewList;
    private BrowserHistory browserHistory;
    private List<BrowserHistoryView> browserHistoryViewList;
    private Comment comment;
    private List<CommentView> commentViewList;
    private List<Comment> commentList;

    private Coupon coupon;
    private List<Coupon> couponList;
    private BuyerCoupon buyerCoupon;
    private List<BuyerCouponView> buyerCouponViewList;
    private List<Article> articleList;
    private Article article;
    private List<BuyerMessage> buyerMessageList;
    private BuyerMessage buyerMessage;
    private List<BuyerMessageView> buyerMessageViewList;
    private OrderReturn orderReturn;
    private List<OrderReturn> orderReturnList;
    private List<ComplexOrderReturn> complexOrderReturnList;

    private Cart cart;
    private Map<String, ShopAndGoodsItemList> cartMap;

    Map<String, GoodsType> goodsTypeMap;
    private List<Goods> goodsList;

    private CommissionDayRecord commissionDayRecord;
    private List<CommissionDayRecord> commissionDayRecordList;
    private CommissionMonthRecord commissionMonthRecord;
    private List<CommissionMonthRecord> commissionMonthRecordList;

    private PreCommissionDayRecord preCommissionDayRecord;
    private List<PreCommissionDayRecord> preCommissionDayRecordList;
    private PreCommissionMonthRecord preCommissionMonthRecord;
    private List<PreCommissionMonthRecord> preCommissionMonthRecordList;

    private List<Advertisement> m_h1_advertisementList;
    private List<Advertisement> m_h2_advertisementList;
    private List<Advertisement> m_p1_advertisementList;

    private List<Buyer> buyerList;

    // 重复通知过滤 时效60秒
    private static Set<String> expireSet = new HashSet<>(60);

    public BuyerAction()
    {
        json = new HashMap<String, Object>();
    }

    public String get_shop_typeid_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        String typeId_pass = getRequest().getParameter("tid");
        if (CM.validIsEmpty(typeId_pass))
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        List<String> typeIdList = Arrays.asList(typeId_pass.split(","));
        if (typeIdList.size() == 0)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        String orderByStr_pass = getRequest().getParameter("orderby");
        if (CM.validIsEmpty(orderByStr_pass))
        {
            orderByStr_pass = goodsDAO.GOODS_SALES_NUMBER;
        }

        String status = "销售中";
        int onePageSize = 20;
        List<Goods> resList = null;
        int countTemp = 0;
        resList = goodsDAO.getListByIndexAndPageSizeAndStatusAndTypeIdListAndOrderBy(index, onePageSize, status, typeIdList, orderByStr_pass);
        countTemp = goodsDAO.getGoodsTotalCountByStatusAndTypeIdListAndOrderBy(status, typeIdList, orderByStr_pass);
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            setGoodsList(null);
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            setGoodsList(null);
            return SUCCESS;
        }
        setGoodsList(resList);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);

        int oneColumnSize = 4;
        int currentPageCount = countTemp < onePageSize ? countTemp : onePageSize;
        int rowNum = currentPageCount % oneColumnSize == 0 ? currentPageCount / oneColumnSize : currentPageCount / oneColumnSize + 1;
        setRowSize(rowNum);
        return SUCCESS;
    }

    public String get_shop_search_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }
        String keyword_pass = getRequest().getParameter("k");
        if (CM.validIsEmpty(keyword_pass))
        {
            info = "参数有误，暂未查到。";
            setGoodsList(null);
            return SUCCESS;
        }

        String orderByStr_pass = getRequest().getParameter("orderby");
        if (CM.validIsEmpty(orderByStr_pass))
        {
            orderByStr_pass = goodsDAO.GOODS_SALES_NUMBER;
        }

        String status = "销售中";
        int onePageSize = 20;
        List<Goods> resList = null;
        int countTemp = 0;
        resList = goodsDAO.getListByIndexAndPageSizeAndStatusAndKeywordAndOrderBy(index, onePageSize, status, keyword_pass, orderByStr_pass);
        countTemp = goodsDAO.getGoodsTotalCountByStatusAndKeywordAndOrderBy(status, keyword_pass, orderByStr_pass);
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            setGoodsList(null);
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            setGoodsList(null);
            return SUCCESS;
        }
        setGoodsList(resList);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);

        int oneColumnSize = 4;
        int currentPageCount = countTemp < onePageSize ? countTemp : onePageSize;
        int rowNum = currentPageCount % oneColumnSize == 0 ? currentPageCount / oneColumnSize : currentPageCount / oneColumnSize + 1;
        setRowSize(rowNum);
        return SUCCESS;
    }

    public String get_help_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        int onePageSize = 20;
        List<Article> resList = null;
        int countTemp = 0;
        resList = articleDAO.getListByIndexAndPageSizeAnd_keyword(index, onePageSize, null);
        countTemp = articleDAO.getTotalCountBy_keyword(null);
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            setArticleList(null);
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            setArticleList(null);
            return SUCCESS;
        }
        setArticleList(resList);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String get_goods()
    {
        String actionName = ServletActionContext.getActionMapping().getName();
        Goods goodsTemp = goodsDAO.findById(actionName);
        if (goodsTemp == null || !goodsTemp.getGoodsStatus().equals("销售中"))
        {
            return GLOBAL_RESULT_GOODS_DOWN;
        }
        setGoods(goodsTemp);

        List<Comment> commentListTemp = commentDAO.getListByGoodsIdAndIndexAndPageSize(goodsTemp.getGoodsId(), 1, 3);
        setCommentList(commentListTemp);

        List<BuyerMessage> buyerMessageListTemp = buyerMessageDAO.getListByGoodsIdAndStatusAndIndexAndPageSize(goodsTemp.getGoodsId(), IStatus.BUYER_MESSAGE_STATUS_HAVE_REPLYED, 1, 3);
        setBuyerMessageList(buyerMessageListTemp);
        return SUCCESS;
    }

    public String get_help()
    {
        String actionName = ServletActionContext.getActionMapping().getName();
        Article articleTemp = articleDAO.findById(actionName);
        if (articleTemp == null)
        {
            return GLOBAL_RESULT_USER_404;
        }
        setArticle(articleTemp);
        return SUCCESS;
    }

    public String u_add_to_shoppingcar()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getCart() == null || CM.validIsEmpty(getCart().getGoodsId()))
        {
            info = "没有找到商品必要信息。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Goods goodsTemp = goodsDAO.findById(getCart().getGoodsId());
        if (goodsTemp == null || !goodsTemp.getGoodsStatus().equals("销售中"))
        {
            info = "没有找到此商品或此商品已下架。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        // 检查商品库存是否足够
        if (goodsTemp.getGoodsInventoryNumber() < getCart().getGoodsNumber())
        {
            info = "商品库存仅剩" + goodsTemp.getGoodsInventoryNumber() + "件。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        Cart cartTemp = cartDAO.findByGoodsIdAndBuyerId(getCart().getGoodsId(), buyerSession.getBuyerId());
        if (cartTemp == null)
        {
            cartTemp = new Cart();
            cartTemp.setCartId(CM.getRandomTwentyFivePrimaryKeyId());
            cartTemp.setGoodsId(getCart().getGoodsId());
            cartTemp.setGoodsNumber(getCart().getGoodsNumber());
            cartTemp.setBuyerId(buyerSession.getBuyerId());
            cartTemp.setCartAddTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));

        }
        else
        {
            // 如果之前已经存在此商品,检查之前和现在添加的数量之和是否超过库存
            if (goodsTemp.getGoodsInventoryNumber() < (cartTemp.getGoodsNumber() + getCart().getGoodsNumber()))
            {
                info = "商品库存仅剩" + goodsTemp.getGoodsInventoryNumber() + "件。您之前已经添加过" + cartTemp.getGoodsNumber() + "件。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }
            cartTemp.setGoodsNumber(cartTemp.getGoodsNumber() + getCart().getGoodsNumber());

        }

        Cart cartResult = cartDAO.save(cartTemp);
        if (cartResult == null)
        {
            info = "添加购物车失败。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        int goodsCount = cartDAO.getCartGoodsTotalCount(buyerSession.getBuyerId());
        if (goodsCount > 0)
        {
            json.put("numberchange", goodsCount);
        }

        json.put("success", true);
        return SUCCESS;
    }

    public String u_get_shoppingcar_number()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        int goodsCount = cartDAO.getCartGoodsTotalCount(buyerSession.getBuyerId());

        System.out.println("====>goodsCount:" + goodsCount);

        if (goodsCount > 0)
        {
            json.put("numberchange", goodsCount);
            json.put("success", true);
        }
        else
        {
            json.put("success", false);
        }

        return SUCCESS;
    }

    public String u_get_buyer_collection_number()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        int collectionCount = buyerCollectionDAO.getBuyerCollectionTotalCount(buyerSession.getBuyerId());

        if (collectionCount > 0)
        {
            json.put("numberchange", collectionCount);
            json.put("success", true);
        }
        else
        {
            json.put("success", false);
        }
        return SUCCESS;
    }

    public String u_get_order_number()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        String status = getRequest().getParameter("s");
        int countTemp = 0;

        if (CM.validIsEmpty(status))
        {
            countTemp = orderDAO.getTotalCountByBuyerId(buyerSession.getBuyerId());
        }
        else
        {
            countTemp = orderDAO.getTotalCountByBuyerIdAndStatus(buyerSession.getBuyerId(), status);
        }

        if (countTemp > 0)
        {
            json.put("numberchange", countTemp);
            json.put("success", true);
        }
        else
        {
            json.put("success", false);
        }
        return SUCCESS;
    }

    public String u_get_coupon_number()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        String status = getRequest().getParameter("s");
        int countTemp = 0;

        if (CM.validIsEmpty(status))
        {
            countTemp = buyerCouponDAO.getTotalCountByBuyerId(buyerSession.getBuyerId());
        }
        else
        {
            countTemp = buyerCouponDAO.getTotalCountByBuyerIdAndCouponStatus(buyerSession.getBuyerId(), status);
        }

        if (countTemp > 0)
        {
            json.put("numberchange", countTemp);
            json.put("success", true);
        }
        else
        {
            json.put("success", false);
        }
        return SUCCESS;
    }

    public String show_shopping_car()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        List<Cart> cartListFromDB = cartDAO.findByBuyerId(buyerSession.getBuyerId());
        Map<String, ShopAndGoodsItemList> cartMapTemp = new LinkedHashMap<String, ShopAndGoodsItemList>();
        for (Cart ctTemp : cartListFromDB)
        {
            Goods goodsFromDB = goodsDAO.findById(ctTemp.getGoodsId());
            if (goodsFromDB.getGoodsStatus().equals(IStatus.GOODS_IS_SOLD_OUT))
            {
                cartDAO.delete(ctTemp);
                continue;
            }

            // 如果Map中没有此超市的话新建之后再加入进去
            if (cartMapTemp.get(goodsFromDB.getGoodsOperationMode()) == null)
            {
                ShopAndGoodsItemList saglTemp = new ShopAndGoodsItemList();
                saglTemp.setOperationMode(goodsFromDB.getGoodsOperationMode());

                List<GoodsItem> gdsListTemp = new ArrayList<GoodsItem>();
                GoodsItem gdItemTemp = new GoodsItem(goodsFromDB, ctTemp.getGoodsNumber(), ctTemp.getCartAddTime());
                gdsListTemp.add(gdItemTemp);
                saglTemp.setGoodsItemList(gdsListTemp);
                cartMapTemp.put(goodsFromDB.getGoodsOperationMode(), saglTemp);
            }
            // 如果Map中已经存在此超市的话就直接加入进去
            else
            {
                GoodsItem gdItemTemp = new GoodsItem(goodsFromDB, ctTemp.getGoodsNumber(), ctTemp.getCartAddTime());
                cartMapTemp.get(goodsFromDB.getGoodsOperationMode()).getGoodsItemList().add(gdItemTemp);
            }
        }

        setCartMap(cartMapTemp);
        return SUCCESS;
    }

    public String u_update_goods_in_shoppingcar()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getCart() == null || CM.validIsEmpty(getCart().getGoodsId()))
        {
            info = "没有找到此商品。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        Cart cartTemp = cartDAO.findByGoodsIdAndBuyerId(getCart().getGoodsId(), buyerSession.getBuyerId());
        if (cartTemp == null)
        {
            info = "没有找到此商品。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        cartTemp.setGoodsNumber(getCart().getGoodsNumber());
        Cart cartResult = cartDAO.save(cartTemp);
        if (cartResult == null)
        {
            info = "更新商品数量失败。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        json.put("success", true);
        return SUCCESS;
    }

    public String u_delete_from_shoppingcar()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (CM.validIsEmpty(getCommonStr()))
        {
            info = "请先选择商品。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        String[] goodsIdArray = getCommonStr().split(",");
        List<String> goodsIdList = new ArrayList<String>();
        for (String iStriTemp : goodsIdArray)
        {
            goodsIdList.add(iStriTemp);
        }
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        int deleResult = cartDAO.deleteByGoodsIdsListAndBuyerId(goodsIdList, buyerSession.getBuyerId());
        if (deleResult == IResult.DELETE_EXCEPTION)
        {
            info = "从购物车中删除商品失败，请刷新页面重新尝试。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        json.put("success", true);
        return SUCCESS;
    }

    public String confirm_order()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        String[] goodsIdArray = getCommonStr().split(",");
        List<String> goodsIdList = new ArrayList<String>();
        for (String iStriTemp : goodsIdArray)
        {
            goodsIdList.add(iStriTemp);
        }
        Shop shopApplication = (Shop) getApplication().getAttribute("shopApplication");
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        List<Cart> cartListFromDB = cartDAO.findByBuyerId(buyerSession.getBuyerId());
        Map<String, ShopAndGoodsItemList> cartMapTemp = new LinkedHashMap<String, ShopAndGoodsItemList>();
        BigDecimal allTotalPriceTemp = new BigDecimal(0);
        for (Cart ctTemp : cartListFromDB)
        {
            if (goodsIdList.contains(ctTemp.getGoodsId()))
            {
                Goods goodsFromDB = goodsDAO.findById(ctTemp.getGoodsId());

                if (goodsFromDB.getGoodsStatus().equals(IStatus.GOODS_IS_SOLD_OUT))
                {
                    cartDAO.delete(ctTemp);
                    continue;
                }

                // 如果Map中没有此超市的话新建之后再加入进去
                if (cartMapTemp.get(goodsFromDB.getGoodsOperationMode()) == null)
                {
                    ShopAndGoodsItemList saglTemp = new ShopAndGoodsItemList();
                    saglTemp.setOperationMode(goodsFromDB.getGoodsOperationMode());

                    List<GoodsItem> gdsListTemp = new ArrayList<GoodsItem>();
                    GoodsItem gdItemTemp = new GoodsItem(goodsFromDB, ctTemp.getGoodsNumber(), ctTemp.getCartAddTime());
                    gdsListTemp.add(gdItemTemp);
                    saglTemp.setGoodsItemList(gdsListTemp);
                    cartMapTemp.put(goodsFromDB.getGoodsOperationMode(), saglTemp);
                }
                // 如果Map中已经存在此超市的话就直接加入进去
                else
                {
                    GoodsItem gdItemTemp = new GoodsItem(goodsFromDB, ctTemp.getGoodsNumber(), ctTemp.getCartAddTime());
                    cartMapTemp.get(goodsFromDB.getGoodsOperationMode()).getGoodsItemList().add(gdItemTemp);
                }
            }
        }

        Calendar cal_now = Calendar.getInstance();
        cal_now.set(Calendar.HOUR_OF_DAY, 0);
        cal_now.set(Calendar.MINUTE, 0);
        cal_now.set(Calendar.SECOND, 0);
        Date start_time = cal_now.getTime();

        cal_now.set(Calendar.HOUR_OF_DAY, 23);
        cal_now.set(Calendar.MINUTE, 59);
        cal_now.set(Calendar.SECOND, 59);
        Date end_time = cal_now.getTime();

        int allGoodsNumber = 0;
        setCanSubmitOrder(true);
        setMessage("");
        Iterator<Entry<String, ShopAndGoodsItemList>> iter = cartMapTemp.entrySet().iterator();
        while (iter.hasNext())
        {
            Map.Entry<String, ShopAndGoodsItemList> object = iter.next();
            String operationMode = object.getValue().getOperationMode();
            List<GoodsItem> carGoodsItemListTemp = object.getValue().getGoodsItemList();

            BigDecimal shopTotalPrice = new BigDecimal(0);
            int goodsTotalNumber = 0;
            // 遍历这个店铺的所有商品
            for (GoodsItem goodsItem : carGoodsItemListTemp)
            {
                shopTotalPrice = shopTotalPrice.add(new BigDecimal(MathExtend.multiply(goodsItem.getGoods().getGoodsPrice(), goodsItem.getNumber())));
                if (goodsItem.getNumber() > goodsItem.getGoods().getGoodsInventoryNumber())
                {
                    setMessage(getMessage() + "\"" + operationMode + "\"中的商品\"" + goodsItem.getGoods().getGoodsName() + "\"的库存仅为：" + goodsItem.getGoods().getGoodsInventoryNumber() + "件。当前购买" + goodsItem.getNumber() + "件，请返回购物车修改数量。</br>");
                    setCanSubmitOrder(false);
                }
                goodsTotalNumber += goodsItem.getNumber();
            }
            allGoodsNumber += goodsTotalNumber;

            allTotalPriceTemp = allTotalPriceTemp.add(shopTotalPrice);
            switch (operationMode)
            {
                case IStatus.OPERATION_MODE_ZY:
                    if (MathExtend.subtract(shopTotalPrice.doubleValue(), shopApplication.getQianhuiMinLimit().doubleValue()) < 0)
                    {
                        setCanSubmitOrder(false);
                        setMessage(getMessage() + "\"" + operationMode + "\"的起送价为：" + shopApplication.getQianhuiMinLimit() + "元，当前已购物：" + shopTotalPrice.setScale(2, BigDecimal.ROUND_HALF_UP) + "元。</br>");
                    }
                    break;
                case IStatus.OPERATION_MODE_MZC:
                    if (goodsTotalNumber < shopApplication.getMzcMinNumber())
                    {
                        setCanSubmitOrder(false);
                        setMessage(getMessage() + "\"" + operationMode + "\"的最低购买数量为：" + shopApplication.getMzcMinNumber() + "件，当前已购物：" + goodsTotalNumber + "件。</br>");
                    }

                    break;

                default:
                    break;
            }

            // （1）每张订单不超过￥2000元。
            if (shopTotalPrice.doubleValue() > 2000)
            {
                setCanSubmitOrder(false);
                setMessage(getMessage() + "每个订单不超过2000元。</br>");
            }

        }

        setAllTotalPrice(allTotalPriceTemp.setScale(2, BigDecimal.ROUND_HALF_UP));
        setCartMap(cartMapTemp);

        BuyerAddress buyerAddressTemp = buyerAddressDAO.getDefaultAddressByBuyerId(buyerSession.getBuyerId());
        setBuyerAddress(buyerAddressTemp);
        List<BuyerAddress> buyerAddressListTemp = buyerAddressDAO.findByBuyerId(buyerSession.getBuyerId());
        setBuyerAddressList(buyerAddressListTemp);

        int onePageSize = 20;
        List<BuyerCoupon> resList = null;
        int countTemp = 0;

        resList = buyerCouponDAO.getListByBuyerIdAndCouponStatusAndIndexAndPageSize(buyerSession.getBuyerId(), IStatus.BUYER_COUPON_STATUS_NOT_USED, 1, onePageSize);
        if (resList != null && resList.size() > 0)
        {
            List<BuyerCouponView> buyerCouponViewListTemp = new ArrayList<BuyerCouponView>();
            for (BuyerCoupon bct : resList)
            {
                BuyerCouponView buyerCouponViewTemp = new BuyerCouponView();

                buyerCouponViewTemp.setBuyerCoupon(bct);
                Coupon couponTemp = couponDAO.findById(bct.getCouponId());
                buyerCouponViewTemp.setCoupon(couponTemp);

                buyerCouponViewListTemp.add(buyerCouponViewTemp);
            }

            setBuyerCouponViewList(buyerCouponViewListTemp);
        }

        return SUCCESS;
    }

    public String u_confirm_order_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (CM.validIsEmpty(getCommonStr()))
        {
            info = "无法找到需要提交订单中的商品。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        String buyerPeopleId = getRequest().getParameter("buyerPeopleId");
        String buyerRealName = getRequest().getParameter("buyerRealName");
        String orderSendWay = getRequest().getParameter("orderSendWay");

        if (CM.validIsEmptyWithTrim(buyerPeopleId) || CM.validIsEmptyWithTrim(buyerRealName))
        {
            info = "请填写身份证号和姓名方便发货。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        if (CM.validIsEmptyWithTrim(orderSendWay))
        {
            info = "请选择配送时间方便您收货。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        if (getBuyerAddress() == null || CM.validIsEmpty(getBuyerAddress().getBuyerAddressId()))
        {
            info = "必须选择地址。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        BuyerAddress buyerAddressTemp = buyerAddressDAO.findById(getBuyerAddress().getBuyerAddressId());
        if (buyerAddressTemp == null)
        {
            info = "没有找到此地址。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Calendar cal_now = Calendar.getInstance();
        cal_now.set(Calendar.HOUR_OF_DAY, 0);
        cal_now.set(Calendar.MINUTE, 0);
        cal_now.set(Calendar.SECOND, 0);
        Date start_time = cal_now.getTime();

        cal_now.set(Calendar.HOUR_OF_DAY, 23);
        cal_now.set(Calendar.MINUTE, 59);
        cal_now.set(Calendar.SECOND, 59);
        Date end_time = cal_now.getTime();

        Date month_start_time = start_time;
        Calendar cal_month = Calendar.getInstance();
        cal_month.setTime(month_start_time);
        cal_month.add(Calendar.MONTH, 1);
        Date month_end_time = cal_month.getTime();

        Calendar cal_year = Calendar.getInstance();
        cal_year.set(Calendar.MONTH, 1);
        cal_year.set(Calendar.DAY_OF_MONTH, 1);
        cal_year.set(Calendar.HOUR_OF_DAY, 0);
        cal_year.set(Calendar.MINUTE, 0);
        cal_year.set(Calendar.SECOND, 0);
        Date year_start_time = cal_year.getTime();
        cal_year.add(Calendar.YEAR, 1);
        Date year_end_time = cal_year.getTime();

        String[] goodsIdArray = getCommonStr().split(",");
        List<String> goodsIdList = new ArrayList<String>();
        for (String iStriTemp : goodsIdArray)
        {
            goodsIdList.add(iStriTemp);
        }

        Shop shopApplication = (Shop) getApplication().getAttribute("shopApplication");
        Buyer buyerSessionTemp = (Buyer) getSession().getAttribute("buyerSession");
        Buyer buyerFromDB = buyerDAO.findById(buyerSessionTemp.getBuyerId());
        getSession().setAttribute("buyerSession", buyerFromDB);
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        // 查看是否使用了优惠券
        String buyer_coupon_id = getRequest().getParameter("buyer_coupon_id");
        BuyerCoupon buyerCouponFromDB = null;
        if (CM.validIsEmptyWithTrim(buyer_coupon_id) == false)
        {
            buyerCouponFromDB = buyerCouponDAO.findByBuyerCouponIdAndBuyerId(buyer_coupon_id, buyerSession.getBuyerId());
            if (buyerCouponFromDB == null)
            {
                info = "没有找到此优惠券。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }
            if (buyerCouponFromDB.getBuyerCouponStatus().equals(IStatus.BUYER_COUPON_STATUS_NOT_USED) == false)
            {
                info = "此优惠券已经不能再使用了。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }
        }

        // 查看是否使用了积分
        boolean chooseUsePoints = false;
        String usePoints = getRequest().getParameter("usePoints");
        if (usePoints.equals("true"))
        {
            chooseUsePoints = true;
        }

        List<Cart> cartListFromDB = cartDAO.findByBuyerId(buyerSession.getBuyerId());
        Map<String, ShopAndGoodsItemList> cartMapTemp = new LinkedHashMap<String, ShopAndGoodsItemList>();
        BigDecimal allTotalPriceTemp = new BigDecimal(0);

        List<Cart> cartListNeedDelete = new ArrayList<Cart>();
        for (Cart ctTemp : cartListFromDB)
        {
            if (goodsIdList.contains(ctTemp.getGoodsId()))
            {
                cartListNeedDelete.add(ctTemp);
                Goods goodsFromDB = goodsDAO.findById(ctTemp.getGoodsId());

                // 如果Map中没有此超市的话新建之后再加入进去
                if (cartMapTemp.get(goodsFromDB.getGoodsOperationMode()) == null)
                {
                    ShopAndGoodsItemList saglTemp = new ShopAndGoodsItemList();
                    saglTemp.setOperationMode(goodsFromDB.getGoodsOperationMode());

                    List<GoodsItem> gdsListTemp = new ArrayList<GoodsItem>();
                    GoodsItem gdItemTemp = new GoodsItem(goodsFromDB, ctTemp.getGoodsNumber(), ctTemp.getCartAddTime());
                    gdsListTemp.add(gdItemTemp);
                    saglTemp.setGoodsItemList(gdsListTemp);
                    cartMapTemp.put(goodsFromDB.getGoodsOperationMode(), saglTemp);
                }
                // 如果Map中已经存在此超市的话就直接加入进去
                else
                {
                    GoodsItem gdItemTemp = new GoodsItem(goodsFromDB, ctTemp.getGoodsNumber(), ctTemp.getCartAddTime());
                    cartMapTemp.get(goodsFromDB.getGoodsOperationMode()).getGoodsItemList().add(gdItemTemp);
                }

            }
        }

        if (cartListNeedDelete.size() <= 0)
        {
            info = "没有找到提交订单中的商品。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        List<Order> orderList = new ArrayList<Order>();
        List<OrderGoods> orderGoodsList = new ArrayList<OrderGoods>();
        setCanSubmitOrder(true);
        setMessage("");

        Iterator<Entry<String, ShopAndGoodsItemList>> iter = cartMapTemp.entrySet().iterator();
        while (iter.hasNext())
        {
            Map.Entry<String, ShopAndGoodsItemList> object = iter.next();
            String operationMode = object.getValue().getOperationMode();
            List<GoodsItem> carGoodsItemListTemp = object.getValue().getGoodsItemList();

            BigDecimal shopTotalPrice = new BigDecimal(0);
            int goodsTotalNumber = 0;

            Order orderTemp = new Order();
            orderTemp.setOrderId(CM.getRandomTwentyFivePrimaryKeyId());
            orderTemp.setOrderBuyerName(buyerAddressTemp.getBuyerAddressName());
            orderTemp.setOrderBuyerAddress(buyerAddressTemp.getBuyerAddressDetail());
            orderTemp.setOrderBuyerPhone(buyerAddressTemp.getBuyerAddressPhone());

            orderTemp.setOrderBuyerProvince(buyerAddressTemp.getBuyerAddressProvince());
            orderTemp.setOrderBuyerCity(buyerAddressTemp.getBuyerAddressCity());
            orderTemp.setOrderBuyerDistrict(buyerAddressTemp.getBuyerAddressDistrict());

            orderTemp.setBuyerId(buyerSession.getBuyerId());
            orderTemp.setOperationMode(operationMode);
            orderTemp.setOrderStatus(IStatus.ORDER_TO_BE_PAYED);
            orderTemp.setOrderBuyTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
            orderTemp.setOrderName("");

            orderTemp.setOrderBuyerPeopleId(getBuyerPeopleId());
            orderTemp.setOrderBuyerRealName(getBuyerRealName());
            orderTemp.setOrderSendWay(orderSendWay);

            // 是否有邮费
            boolean has_postage_expense = false;
            // 统计此订单所有商品的税
            BigDecimal order_total_tax = new BigDecimal(0);

            // 遍历这个店铺的所有商品
            for (GoodsItem goodsItem : carGoodsItemListTemp)
            {
                shopTotalPrice = shopTotalPrice.add(new BigDecimal(MathExtend.multiply(goodsItem.getGoods().getGoodsPrice(), goodsItem.getNumber())));
                if (goodsItem.getNumber() > goodsItem.getGoods().getGoodsInventoryNumber())
                {
                    setMessage(getMessage() + "\"" + operationMode + "\"中的商品\"" + goodsItem.getGoods().getGoodsName() + "\"的库存仅为：" + goodsItem.getGoods().getGoodsInventoryNumber() + "件。当前购买" + goodsItem.getNumber() + "件，请返回购物车修改数量。</br>");
                    setCanSubmitOrder(false);
                }
                goodsTotalNumber += goodsItem.getNumber();

                OrderGoods orderGoodsTemp = new OrderGoods();
                orderGoodsTemp.setOrderGoodsId(CM.getRandomTwentyFivePrimaryKeyId());
                orderGoodsTemp.setOrderId(orderTemp.getOrderId());
                orderGoodsTemp.setGoodsId(goodsItem.getGoods().getGoodsId());
                orderGoodsTemp.setGoodsNumber(goodsItem.getNumber());
                orderGoodsTemp.setGoodsUpdateTime(goodsItem.getGoods().getGoodsUpdateTime());
                orderGoodsTemp.setOrderGoodsAddTime(goodsItem.getCartAddTime());
                orderGoodsList.add(orderGoodsTemp);

                orderTemp.setOrderName(CM.getStartNCharacter(orderTemp.getOrderName() + goodsItem.getGoods().getGoodsName() + ";", 100));

                // 判断是否有商品需要邮费
                if (goodsItem.getGoods().getGoodsPostageType() != null && goodsItem.getGoods().getGoodsPostageType().equals(IStatus.POSTAGE_EXPENSE))
                {
                    has_postage_expense = true;
                }
                // 得到此商品的税率
                GoodsType goodsTypeTemp = goodsTypeDAO.findById(goodsItem.getGoods().getGoodsTypeId());
                if (goodsTypeTemp != null && goodsTypeTemp.getGoodsTypeTaxRate() != null && goodsTypeTemp.getGoodsTypeTaxRate() > 0)
                {
                    order_total_tax = order_total_tax.add(new BigDecimal(MathExtend.multiply(goodsItem.getGoods().getGoodsPrice(), goodsItem.getNumber()) * goodsTypeTemp.getGoodsTypeTaxRate()));
                }
            }
            switch (operationMode)
            {
                case IStatus.OPERATION_MODE_ZY:
                    if (MathExtend.subtract(shopTotalPrice.doubleValue(), shopApplication.getQianhuiMinLimit().doubleValue()) < 0)
                    {
                        setCanSubmitOrder(false);
                        setMessage(getMessage() + "\"" + operationMode + "\"的起送价为：" + shopApplication.getQianhuiMinLimit() + "元，当前已购物：" + shopTotalPrice.setScale(2, BigDecimal.ROUND_HALF_UP) + "元。</br>");
                    }
                    break;
                case IStatus.OPERATION_MODE_MZC:
                    if (goodsTotalNumber < shopApplication.getMzcMinNumber())
                    {
                        setCanSubmitOrder(false);
                        setMessage(getMessage() + "\"" + operationMode + "\"的最低购买数量为：" + shopApplication.getMzcMinNumber() + "件，当前已购物：" + goodsTotalNumber + "件。</br>");
                    }
                    break;

                default:
                    break;
            }

            // 设置邮费
            if (has_postage_expense == true)
            {
                orderTemp.setOrderFreight(CM.getProvincePostageByProvinceName(buyerAddressTemp.getBuyerAddressProvince()));
            }
            else
            {
                orderTemp.setOrderFreight(0.0);
            }

            orderTemp.setOrderActualTax(order_total_tax.doubleValue());
            orderTemp.setOrderTax(order_total_tax.doubleValue());
            orderTemp.setOrderOriginalPrice(shopTotalPrice.doubleValue());
            orderTemp.setOrderTotalPrice(shopTotalPrice.doubleValue() + orderTemp.getOrderFreight() + orderTemp.getOrderTax());
            orderList.add(orderTemp);

            allTotalPriceTemp = allTotalPriceTemp.add(new BigDecimal(orderTemp.getOrderTotalPrice()));
        }

        // （4）同一身份证购买金额不超过20000元/年
        double year_peopleId_money = orderDAO.getTotalMoneyByPeopleIdAndBeginTimeAndEndTime(buyerPeopleId, year_start_time, year_end_time);
        if (year_peopleId_money + allTotalPriceTemp.doubleValue() > 20000)
        {
            info = "同一个身份证购买不能超过20000元/年。此身份证今年已购买" + year_peopleId_money + "元";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        setAllTotalPrice(allTotalPriceTemp);
        setCartMap(cartMapTemp);

        List<BuyerCoupon> buyerCouponListForUpdate = new ArrayList<BuyerCoupon>();

        if (buyerCouponFromDB != null)
        {
            Coupon couponTemp = couponDAO.findById(buyerCouponFromDB.getCouponId());
            if (couponTemp.getCouponUseBeginTime().after(Calendar.getInstance().getTime()))
            {
                info = "还没到优惠券的使用时间。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }
            if (couponTemp.getCouponUseEndTime().before(Calendar.getInstance().getTime()))
            {
                info = "已经过了优惠券的使用时间。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }

            if (couponTemp.getCouponType().equals("满减") && couponTemp.getParam1() > allTotalPriceTemp.doubleValue())
            {
                info = "不满足使用条件。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }

            switch (couponTemp.getCouponType())
            {
                case "满减":
                {
                    if (couponTemp.getParam2() >= allTotalPriceTemp.doubleValue())
                    {
                        json.put("tips", "优惠券金额大于订单金额，订单金额降为0.01元，优惠券不找零。");
                        json.put("allTotalPrice", "0.01");
                        for (Order oT : orderList)
                        {
                            oT.setOrderTotalPrice(0.01);
                            oT.setOrderUseCouponId(couponTemp.getCouponId());
                        }
                        buyerCouponFromDB.setBuyerCouponStatus(IStatus.BUYER_COUPON_STATUS_HAVE_USED);
                    }
                    else
                    {
                        allTotalPriceTemp = allTotalPriceTemp.subtract(new BigDecimal(couponTemp.getParam2()));
                        DecimalFormat df = new DecimalFormat("0.00");
                        json.put("allTotalPrice", df.format(allTotalPriceTemp.doubleValue()));
                        for (Order oT : orderList)
                        {
                            if (oT.getOrderTotalPrice() > couponTemp.getParam2())
                            {
                                double now_price = (new BigDecimal(oT.getOrderTotalPrice()).subtract(new BigDecimal(couponTemp.getParam2()))).doubleValue();
                                oT.setOrderTotalPrice(now_price);
                                oT.setOrderUseCouponId(couponTemp.getCouponId());
                                buyerCouponFromDB.setBuyerCouponStatus(IStatus.BUYER_COUPON_STATUS_HAVE_USED);
                                break;
                            }
                        }

                    }
                }
                break;
                case "立减":
                {
                    if (couponTemp.getParam1() >= allTotalPriceTemp.doubleValue())
                    {
                        json.put("tips", "优惠券金额大于订单金额，订单金额降为0.01元，优惠券不找零。");
                        json.put("allTotalPrice", "0.01");
                        for (Order oT : orderList)
                        {
                            oT.setOrderTotalPrice(0.01);
                            oT.setOrderUseCouponId(couponTemp.getCouponId());
                        }
                        buyerCouponFromDB.setBuyerCouponStatus(IStatus.BUYER_COUPON_STATUS_HAVE_USED);
                    }
                    else
                    {
                        allTotalPriceTemp = allTotalPriceTemp.subtract(new BigDecimal(couponTemp.getParam1()));
                        DecimalFormat df = new DecimalFormat("0.00");
                        json.put("allTotalPrice", df.format(allTotalPriceTemp.doubleValue()));
                        for (Order oT : orderList)
                        {
                            if (oT.getOrderTotalPrice() > couponTemp.getParam1())
                            {
                                double now_price = (new BigDecimal(oT.getOrderTotalPrice()).subtract(new BigDecimal(couponTemp.getParam1()))).doubleValue();
                                oT.setOrderTotalPrice(now_price);
                                oT.setOrderUseCouponId(couponTemp.getCouponId());
                                buyerCouponFromDB.setBuyerCouponStatus(IStatus.BUYER_COUPON_STATUS_HAVE_USED);
                                break;
                            }
                        }
                    }
                }
                break;

                default:
                    break;
            }
        }

        if (chooseUsePoints == true)
        {
            for (Order oT : orderList)
            {
                if (oT.getOrderTotalPrice() > (buyerSession.getBuyerPoints() * 0.01))
                {
                    double now_price = (new BigDecimal(oT.getOrderTotalPrice()).subtract(new BigDecimal(buyerSession.getBuyerPoints() * 0.01))).doubleValue();
                    oT.setOrderTotalPrice(now_price);
                    oT.setOrderUsePoints(buyerSession.getBuyerPoints());
                    buyerSession.setBuyerPoints(0);
                    break;
                }
            }
        }

        if (isCanSubmitOrder() == false)
        {
            info = getMessage();
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        if (CM.validIsEmptyWithTrim(buyerPeopleId) == false)
        {
            buyerSession.setBuyerPeopleId(buyerPeopleId);

        }
        if (CM.validIsEmptyWithTrim(buyerRealName) == false)
        {
            buyerSession.setBuyerRealName(buyerRealName);
        }

        List<Order> resOrderList = orderDAO.confirm_order_addOrderAndOrderGoodsListAndDeleteCartListAndSaveBuyer(orderList, orderGoodsList, cartListNeedDelete, buyerCouponFromDB, buyerSession);
        if (resOrderList == null)
        {
            info = "提交订单时出现错误，请稍后重试！";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        // 订单号合并支付
        String ids = "";
        for (Order order : resOrderList)
        {
            ids += order.getOrderId() + ",";
        }
        if (ids.equals(""))
        {
            info = "提交订单时出现错误，请稍后重试！";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerFromDBForUpdate = buyerDAO.findById(buyerSession.getBuyerId());
        getSession().setAttribute("buyerSession", buyerFromDBForUpdate);

        ids = ids.substring(0, ids.length() - 1);
        json.put("success", true);
        json.put("ids", ids);
        return SUCCESS;
    }

    public String u_valid_coupon_for_order_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (CM.validIsEmpty(getCommonStr()))
        {
            info = "无法找到需要提交订单中的商品。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        if (getBuyerAddress() == null || CM.validIsEmpty(getBuyerAddress().getBuyerAddressId()))
        {
            info = "必须选择地址。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        BuyerAddress buyerAddressTemp = buyerAddressDAO.findById(getBuyerAddress().getBuyerAddressId());
        if (buyerAddressTemp == null)
        {
            info = "没有找到此地址。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        String[] goodsIdArray = getCommonStr().split(",");
        List<String> goodsIdList = new ArrayList<String>();
        for (String iStriTemp : goodsIdArray)
        {
            goodsIdList.add(iStriTemp);
        }

        Shop shopApplication = (Shop) getApplication().getAttribute("shopApplication");
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        String buyer_coupon_id = getRequest().getParameter("buyer_coupon_id");
        if (buyer_coupon_id == null)
        {
            info = "请选择优惠券。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        BuyerCoupon buyerCouponFromDB = buyerCouponDAO.findByBuyerCouponIdAndBuyerId(buyer_coupon_id, buyerSession.getBuyerId());
        if (buyerCouponFromDB == null)
        {
            info = "没有找到此优惠券。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        if (buyerCouponFromDB.getBuyerCouponStatus().equals(IStatus.BUYER_COUPON_STATUS_NOT_USED) == false)
        {
            info = "此优惠券已经不能再使用了。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        List<Cart> cartListFromDB = cartDAO.findByBuyerId(buyerSession.getBuyerId());
        Map<String, ShopAndGoodsItemList> cartMapTemp = new LinkedHashMap<String, ShopAndGoodsItemList>();
        BigDecimal allTotalPriceTemp = new BigDecimal(0);

        List<Cart> cartListNeedDelete = new ArrayList<Cart>();
        for (Cart ctTemp : cartListFromDB)
        {
            if (goodsIdList.contains(ctTemp.getGoodsId()))
            {
                cartListNeedDelete.add(ctTemp);
                Goods goodsFromDB = goodsDAO.findById(ctTemp.getGoodsId());

                // 如果Map中没有此超市的话新建之后再加入进去
                if (cartMapTemp.get(goodsFromDB.getGoodsOperationMode()) == null)
                {
                    ShopAndGoodsItemList saglTemp = new ShopAndGoodsItemList();
                    saglTemp.setOperationMode(goodsFromDB.getGoodsOperationMode());

                    List<GoodsItem> gdsListTemp = new ArrayList<GoodsItem>();
                    GoodsItem gdItemTemp = new GoodsItem(goodsFromDB, ctTemp.getGoodsNumber(), ctTemp.getCartAddTime());
                    gdsListTemp.add(gdItemTemp);
                    saglTemp.setGoodsItemList(gdsListTemp);
                    cartMapTemp.put(goodsFromDB.getGoodsOperationMode(), saglTemp);
                }
                // 如果Map中已经存在此超市的话就直接加入进去
                else
                {
                    GoodsItem gdItemTemp = new GoodsItem(goodsFromDB, ctTemp.getGoodsNumber(), ctTemp.getCartAddTime());
                    cartMapTemp.get(goodsFromDB.getGoodsOperationMode()).getGoodsItemList().add(gdItemTemp);
                }

            }
        }

        List<Order> orderList = new ArrayList<Order>();
        List<OrderGoods> orderGoodsList = new ArrayList<OrderGoods>();
        setCanSubmitOrder(true);
        setMessage("");

        Iterator<Entry<String, ShopAndGoodsItemList>> iter = cartMapTemp.entrySet().iterator();
        while (iter.hasNext())
        {
            Map.Entry<String, ShopAndGoodsItemList> object = iter.next();
            String operationMode = object.getValue().getOperationMode();
            List<GoodsItem> carGoodsItemListTemp = object.getValue().getGoodsItemList();

            BigDecimal shopTotalPrice = new BigDecimal(0);
            int goodsTotalNumber = 0;

            Order orderTemp = new Order();
            orderTemp.setOrderId(CM.getRandomTwentyFivePrimaryKeyId());
            orderTemp.setOrderBuyerName(buyerAddressTemp.getBuyerAddressName());
            orderTemp.setOrderBuyerAddress(buyerAddressTemp.getBuyerAddressDetail());
            orderTemp.setOrderBuyerPhone(buyerAddressTemp.getBuyerAddressPhone());
            orderTemp.setBuyerId(buyerSession.getBuyerId());
            orderTemp.setOperationMode(operationMode);
            orderTemp.setOrderStatus(IStatus.ORDER_TO_BE_PAYED);
            orderTemp.setOrderBuyTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
            orderTemp.setOrderName("");
            orderTemp.setOrderFreight(0.0);
            orderTemp.setOrderBuyerPeopleId(getBuyerPeopleId());
            orderTemp.setOrderBuyerRealName(getBuyerRealName());

            // 遍历这个店铺的所有商品
            for (GoodsItem goodsItem : carGoodsItemListTemp)
            {
                shopTotalPrice = shopTotalPrice.add(new BigDecimal(MathExtend.multiply(goodsItem.getGoods().getGoodsPrice(), goodsItem.getNumber())));
                if (goodsItem.getNumber() > goodsItem.getGoods().getGoodsInventoryNumber())
                {
                    setMessage(getMessage() + "\"" + operationMode + "\"中的商品\"" + goodsItem.getGoods().getGoodsName() + "\"的库存仅为：" + goodsItem.getGoods().getGoodsInventoryNumber() + "件。当前购买" + goodsItem.getNumber() + "件，请返回购物车修改数量。</br>");
                    setCanSubmitOrder(false);
                }
                goodsTotalNumber += goodsItem.getNumber();

                OrderGoods orderGoodsTemp = new OrderGoods();
                orderGoodsTemp.setOrderGoodsId(CM.getRandomTwentyFivePrimaryKeyId());
                orderGoodsTemp.setOrderId(orderTemp.getOrderId());
                orderGoodsTemp.setGoodsId(goodsItem.getGoods().getGoodsId());
                orderGoodsTemp.setGoodsNumber(goodsItem.getNumber());
                orderGoodsTemp.setGoodsUpdateTime(goodsItem.getGoods().getGoodsUpdateTime());
                orderGoodsTemp.setOrderGoodsAddTime(goodsItem.getCartAddTime());
                orderGoodsList.add(orderGoodsTemp);

                orderTemp.setOrderName(CM.getStartNCharacter(orderTemp.getOrderName() + goodsItem.getGoods().getGoodsName() + ";", 100));
            }
            allTotalPriceTemp = allTotalPriceTemp.add(shopTotalPrice);
            switch (operationMode)
            {
                case IStatus.OPERATION_MODE_ZY:
                    if (MathExtend.subtract(shopTotalPrice.doubleValue(), shopApplication.getQianhuiMinLimit().doubleValue()) < 0)
                    {
                        setCanSubmitOrder(false);
                        setMessage(getMessage() + "\"" + operationMode + "\"的起送价为：" + shopApplication.getQianhuiMinLimit() + "元，当前已购物：" + shopTotalPrice.setScale(2, BigDecimal.ROUND_HALF_UP) + "元。</br>");
                    }
                    break;
                case IStatus.OPERATION_MODE_MZC:
                    if (goodsTotalNumber < shopApplication.getMzcMinNumber())
                    {
                        setCanSubmitOrder(false);
                        setMessage(getMessage() + "\"" + operationMode + "\"的最低购买数量为：" + shopApplication.getMzcMinNumber() + "件，当前已购物：" + goodsTotalNumber + "件。</br>");
                    }
                    break;

                default:
                    break;
            }

            orderTemp.setOrderTotalPrice(shopTotalPrice.doubleValue());
            orderList.add(orderTemp);

        }

        Coupon couponTemp = couponDAO.findById(buyerCouponFromDB.getCouponId());
        if (couponTemp.getCouponUseBeginTime().after(Calendar.getInstance().getTime()))
        {
            info = "还没到优惠券的使用时间。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        if (couponTemp.getCouponUseEndTime().before(Calendar.getInstance().getTime()))
        {
            info = "已经过了优惠券的使用时间。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        if (couponTemp.getCouponType().equals("满减") && couponTemp.getParam1() > allTotalPriceTemp.doubleValue())
        {
            info = "不满足使用条件。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        switch (couponTemp.getCouponType())
        {
            case "满减":
            {
                if (couponTemp.getParam2() >= allTotalPriceTemp.doubleValue())
                {
                    json.put("tips", "优惠券金额大于订单金额，订单金额降为0.01元，优惠券不找零。");
                    json.put("allTotalPrice", "0.01");
                }
                else
                {
                    allTotalPriceTemp = allTotalPriceTemp.subtract(new BigDecimal(couponTemp.getParam2()));
                    DecimalFormat df = new DecimalFormat("0.00");
                    json.put("allTotalPrice", df.format(allTotalPriceTemp.doubleValue()));
                }
            }
            break;
            case "立减":
            {
                if (couponTemp.getParam1() >= allTotalPriceTemp.doubleValue())
                {
                    json.put("tips", "优惠券金额大于订单金额，订单金额降为0.01元，优惠券不找零。");
                    json.put("allTotalPrice", "0.01");
                }
                else
                {
                    allTotalPriceTemp = allTotalPriceTemp.subtract(new BigDecimal(couponTemp.getParam1()));
                    DecimalFormat df = new DecimalFormat("0.00");
                    json.put("allTotalPrice", df.format(allTotalPriceTemp.doubleValue()));
                }
            }
            break;

            default:
                break;
        }

        json.put("success", true);
        return SUCCESS;
    }

    public String u_confirm_receive_order_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (CM.validIsEmpty(getCommonStr()))
        {
            info = "没有找到需要确认收货的订单。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        String[] goodsIdArray = getCommonStr().split(",");
        List<String> goodsIdList = Arrays.asList(goodsIdArray);

        if (goodsIdList.size() > 20)
        {
            info = "最多支持20个订单同时确认收货。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Shop shopApplication = (Shop) getApplication().getAttribute("shopApplication");
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        List<Order> orderListTemp = orderDAO.findByIdsAndBuyerId(goodsIdList, buyerSession.getBuyerId());
        for (Order orderT : orderListTemp)
        {
            if (orderT.getOrderStatus().equals(IStatus.ORDER_TO_BE_RECEIVED))
            {
                orderT.setOrderStatus(IStatus.ORDER_TO_BE_COMMENTED);
                orderT.setOrderReceiveTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
            }
        }

        List<Order> orderListResult = orderDAO.saveList(orderListTemp);
        if (orderListResult == null)
        {
            info = "确认收货失败，请稍后重试。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        json.put("success", true);
        return SUCCESS;
    }

    public String u_confirm_receive_seller_order_return_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (CM.validIsEmpty(getCommonStr()))
        {
            info = "没有找到退换货订单。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        String[] goodsIdArray = getCommonStr().split(",");
        List<String> goodsIdList = Arrays.asList(goodsIdArray);

        if (goodsIdList.size() > 20)
        {
            info = "最多支持20个退换货订单同时确认收货。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Shop shopApplication = (Shop) getApplication().getAttribute("shopApplication");
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        List<OrderReturn> orderReturnListTemp = orderReturnDAO.findByIdsAndBuyerId(goodsIdList, buyerSession.getBuyerId());
        List<Order> orderListTemp = new ArrayList<Order>();
        for (OrderReturn orTemp : orderReturnListTemp)
        {
            if (orTemp.getOrderReturnStatus().equals(IStatus.ORDER_RETURN_SELLER_PROCESSING) && orTemp.getOrderReturnType().equals("换货"))
            {
                orTemp.setOrderReturnStatus(IStatus.ORDER_RETURN_HAVE_BEEN_COMPLETED);
                Order orderTemp = orderDAO.findById(orTemp.getOrderId());
                orderTemp.setOrderStatus(IStatus.ORDER_TO_BE_COMMENTED);
                orderListTemp.add(orderTemp);
            }
        }

        List<OrderReturn> orderReturnListResult = orderReturnDAO.batch_save_return_and_order(orderReturnListTemp, orderListTemp);
        if (orderReturnListResult == null)
        {
            info = "确认收货失败，请稍后重试。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        json.put("success", true);
        return SUCCESS;
    }

    public String post_comment()
    {
        String id_pass = getRequest().getParameter("id");
        if (CM.validIsEmpty(id_pass))
        {
            return GLOBAL_RESULT_404;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        Order orderResult = orderDAO.findByIdAndBuyerId(id_pass, buyerSession.getBuyerId());
        if (orderResult == null || !orderResult.getOrderStatus().equals(IStatus.ORDER_TO_BE_COMMENTED))
        {
            return GLOBAL_RESULT_404;
        }

        ComplexOrder complexOrderTemp = new ComplexOrder();
        complexOrderTemp.setOrder(orderResult);

        List<GoodsHistoryItem> goodsHistoryItemList = new ArrayList<GoodsHistoryItem>();
        List<OrderGoods> orderGoodsList = orderGoodsDAO.findByProperty(OrderGoodsDAO.ORDER_ID, orderResult.getOrderId());
        for (OrderGoods orderGoods : orderGoodsList)
        {
            GoodsHistoryItem goodsHistoryItem = new GoodsHistoryItem();
            GoodsHistory goodsHistoryTemp = goodsHistoryDAO.findByGoodsIdAndGoodsUpdateTime(orderGoods.getGoodsId(), orderGoods.getGoodsUpdateTime());
            goodsHistoryItem.setGoodsHistory(goodsHistoryTemp);
            goodsHistoryItem.setNumber(orderGoods.getGoodsNumber());
            goodsHistoryItem.setCommentId(orderGoods.getCommentId());
            goodsHistoryItemList.add(goodsHistoryItem);
        }
        complexOrderTemp.setGoodsHistoryItemList(goodsHistoryItemList);

        setComplexOrder(complexOrderTemp);
        return SUCCESS;
    }

    public String post_message()
    {
        String id_pass = getRequest().getParameter("id");
        if (CM.validIsEmpty(id_pass))
        {
            return GLOBAL_RESULT_404;
        }

        Goods goodsTemp = goodsDAO.findById(id_pass);
        if (goodsTemp == null || !goodsTemp.getGoodsStatus().equals("销售中"))
        {
            return GLOBAL_RESULT_GOODS_DOWN;
        }
        setGoods(goodsTemp);
        return SUCCESS;
    }

    public String u_post_comment_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getComment() == null || CM.validIsEmpty(getComment().getOrderId()))
        {
            info = "评论失败，请检查输入项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        String[] goodsIdsArray = getRequest().getParameterValues("goodsIds");
        String[] commentsArray = getRequest().getParameterValues("comments");
        String[] commentDescriptionStarsArray = getRequest().getParameterValues("commentDescriptionStars");
        int[] descriptionStarsIntArray = new int[commentDescriptionStarsArray.length];
        for (int i = 0; i < descriptionStarsIntArray.length; i++)
        {
            descriptionStarsIntArray[i] = Integer.parseInt(commentDescriptionStarsArray[i]);
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        Order orderResult = orderDAO.findByIdAndBuyerId(getComment().getOrderId(), buyerSession.getBuyerId());
        if (orderResult == null || !orderResult.getOrderStatus().equals(IStatus.ORDER_TO_BE_COMMENTED))
        {
            info = "没有找到此订单或该订单已评论过。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        List<OrderGoods> orderGoodsList = orderGoodsDAO.findByProperty(OrderGoodsDAO.ORDER_ID, orderResult.getOrderId());

        List<Comment> commentListTemp = new ArrayList<Comment>();
        for (OrderGoods orderGoods : orderGoodsList)
        {
            for (int i = 0; i < goodsIdsArray.length; i++)
            {
                if (orderGoods.getGoodsId().equals(goodsIdsArray[i]))
                {
                    Comment commentTemp = new Comment();
                    commentTemp.setCommentId(CM.getRandomTwentyFivePrimaryKeyId());
                    commentTemp.setCommentDescriptionStar(descriptionStarsIntArray[i]);
                    commentTemp.setCommentServiceStar(getComment().getCommentServiceStar());
                    commentTemp.setCommentDeliverStar(getComment().getCommentDeliverStar());
                    commentTemp.setCommentLogisticsStar(getComment().getCommentLogisticsStar());
                    commentTemp.setCommentCourierStar(getComment().getCommentCourierStar());
                    commentTemp.setCommentContent(commentsArray[i]);
                    commentTemp.setCommentContentTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
                    commentTemp.setBuyerId(buyerSession.getBuyerId());
                    commentTemp.setGoodsId(orderGoods.getGoodsId());
                    commentTemp.setOrderId(orderResult.getOrderId());

                    commentListTemp.add(commentTemp);
                    orderGoods.setCommentId(commentTemp.getCommentId());
                }
            }
        }
        orderResult.setOrderStatus(IStatus.ORDER_HAVE_BEEN_COMPLETED);
        orderResult.setOrderCompleteTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));

        Order post_order_result = orderDAO.post_order_and_post_comments(orderResult, orderGoodsList, commentListTemp);

        if (post_order_result == null)
        {
            info = "发表评论失败，请稍后重试。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        json.put("success", true);
        return SUCCESS;
    }

    public String u_post_message_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        String goodsId = getRequest().getParameter("goodsId");
        String content = getRequest().getParameter("content");

        List<String> validStrList = new ArrayList<String>();
        validStrList.add(goodsId);
        validStrList.add(content);
        if (CM.validAtLeastOneIsEmpty(validStrList))
        {
            info = "商品id和留言内容都是必填项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        BuyerMessage buyerMessageTemp = new BuyerMessage();
        buyerMessageTemp.setBuyerMessageId(CM.getRandomTwentyFivePrimaryKeyId());
        buyerMessageTemp.setBuyerMessageContent(content);
        buyerMessageTemp.setBuyerMessageTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
        buyerMessageTemp.setBuyerId(buyerSession.getBuyerId());
        buyerMessageTemp.setGoodsId(goodsId);
        buyerMessageTemp.setBuyerMessageStatus(IStatus.BUYER_MESSAGE_STATUS_TO_BE_HANDLED);

        BuyerMessage buyerMessageRes = buyerMessageDAO.save(buyerMessageTemp);
        if (buyerMessageRes == null)
        {
            info = "提交留言失败。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        json.put("success", true);
        return SUCCESS;
    }

    public String u_apply_for_return_order_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getOrderReturn() == null)
        {
            info = "标有*的都是必填项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        List<String> validStrList = new ArrayList<String>();
        validStrList.add(getOrderReturn().getOrderId());
        validStrList.add(getOrderReturn().getOrderReturnType());
        validStrList.add(getOrderReturn().getOrderReturnReason());
        if (CM.validAtLeastOneIsEmpty(validStrList))
        {
            info = "标有*的都是必填项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        Order orderFromDB = orderDAO.findByIdAndBuyerId(getOrderReturn().getOrderId(), buyerSession.getBuyerId());
        if (orderFromDB == null)
        {
            info = "没有找到此订单。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        if (orderFromDB.getOrderStatus().equals(IStatus.ORDER_TO_BE_COMMENTED) == false)
        {
            info = "待评价状态的订单才能退换货。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        OrderReturn orderReturnTemp = new OrderReturn();
        orderReturnTemp.setOrderReturnId(CM.getRandomTwentyFivePrimaryKeyId());
        orderReturnTemp.setOrderId(getOrderReturn().getOrderId());
        orderReturnTemp.setOrderReturnType(getOrderReturn().getOrderReturnType());
        orderReturnTemp.setOrderReturnReason(getOrderReturn().getOrderReturnReason());
        orderReturnTemp.setOrderReturnBeginTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
        orderReturnTemp.setBuyerId(buyerSession.getBuyerId());
        orderReturnTemp.setOrderReturnStatus(IStatus.ORDER_RETURN_APPLY_VERIFYING);

        orderFromDB.setOrderStatus(IStatus.ORDER_RETURN_PROCESSING);

        OrderReturn orderReturnRes = orderReturnDAO.batch_save_return_and_order(orderReturnTemp, orderFromDB);
        if (orderReturnRes == null)
        {
            info = "提交申请失败。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        // 给微信客服人员推送退货申请提醒
        CP.push_order_return_apply_info(orderFromDB, orderReturnRes);

        json.put("success", true);
        return SUCCESS;
    }

    public String u_write_buyer_express_info_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getOrderReturn() == null)
        {
            info = "标有*的都是必填项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        List<String> validStrList = new ArrayList<String>();
        validStrList.add(getOrderReturn().getOrderReturnId());
        validStrList.add(getOrderReturn().getOrderBuyerExpressCompany());
        validStrList.add(getOrderReturn().getOrderBuyerExpressNumber());
        if (CM.validAtLeastOneIsEmpty(validStrList))
        {
            info = "标有*的都是必填项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        OrderReturn orderReturnFromDB = orderReturnDAO.findByIdAndBuyerId(getOrderReturn().getOrderReturnId(), buyerSession.getBuyerId());
        if (orderReturnFromDB == null)
        {
            info = "没有找到此退换货订单。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        if (orderReturnFromDB.getOrderReturnStatus().equals(IStatus.ORDER_RETURN_BUYER_RETURNING) == false)
        {
            info = "只有买家退换货中的退换货订单才能填写退换货快递信息。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        orderReturnFromDB.setOrderBuyerExpressCompany(getOrderReturn().getOrderBuyerExpressCompany());
        orderReturnFromDB.setOrderBuyerExpressNumber(getOrderReturn().getOrderBuyerExpressNumber());

        OrderReturn orderReturnRes = orderReturnDAO.save(orderReturnFromDB);
        if (orderReturnRes == null)
        {
            info = "操作失败。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        json.put("success", true);
        return SUCCESS;
    }

    public String pay()
    {
        String ids = getRequest().getParameter("ids");
        if (ids == null)
        {
            return "toCart";
        }
        String[] idsArray = ids.split(",");
        List<String> idsList = Arrays.asList(idsArray);

        if (idsList.size() <= 0)
        {
            return "toCart";
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        List<Order> resOrderList = orderDAO.findByIdsAndBuyerId(idsList, buyerSession.getBuyerId());

        if (resOrderList == null)
        {
            return "toCart";
        }

        BigDecimal orderTotalMoneyTemp = new BigDecimal(0);

        for (Order order : resOrderList)
        {
            orderTotalMoneyTemp = orderTotalMoneyTemp.add(new BigDecimal(order.getOrderTotalPrice()));
        }

        setAllTotalPrice(orderTotalMoneyTemp);
        setOrderList(resOrderList);

        return SUCCESS;
    }

    public String show_order_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        String status = getRequest().getParameter("s");
        int onePageSize = 20;
        List<Order> resList = null;
        int countTemp = 0;

        if (CM.validIsEmpty(status))
        {
            resList = orderDAO.getListByBuyerIdAndIndexAndPageSize(buyerSession.getBuyerId(), index, onePageSize);
            countTemp = orderDAO.getTotalCountByBuyerId(buyerSession.getBuyerId());
        }
        else
        {
            resList = orderDAO.getListByBuyerIdAndIndexAndPageSizeAndStatus(buyerSession.getBuyerId(), index, onePageSize, status);
            countTemp = orderDAO.getTotalCountByBuyerIdAndStatus(buyerSession.getBuyerId(), status);
        }
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        List<ComplexOrder> complexOrderListTemp = new ArrayList<ComplexOrder>();
        for (Order orderTTT : resList)
        {
            ComplexOrder complexOrderTemp = new ComplexOrder();
            complexOrderTemp.setOrder(orderTTT);

            List<GoodsHistoryItem> goodsHistoryItemList = new ArrayList<GoodsHistoryItem>();
            List<OrderGoods> orderGoodsList = orderGoodsDAO.findByProperty(OrderGoodsDAO.ORDER_ID, orderTTT.getOrderId());
            for (OrderGoods orderGoods : orderGoodsList)
            {
                GoodsHistoryItem goodsHistoryItem = new GoodsHistoryItem();
                GoodsHistory goodsHistoryTemp = goodsHistoryDAO.findByGoodsIdAndGoodsUpdateTime(orderGoods.getGoodsId(), orderGoods.getGoodsUpdateTime());
                goodsHistoryItem.setGoodsHistory(goodsHistoryTemp);
                goodsHistoryItem.setNumber(orderGoods.getGoodsNumber());
                goodsHistoryItem.setCommentId(orderGoods.getCommentId());
                goodsHistoryItemList.add(goodsHistoryItem);
            }
            complexOrderTemp.setGoodsHistoryItemList(goodsHistoryItemList);

            complexOrderListTemp.add(complexOrderTemp);
        }

        setComplexOrderList(complexOrderListTemp);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_order_return_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        int onePageSize = 20;
        List<OrderReturn> resList = null;
        int countTemp = 0;

        resList = orderReturnDAO.getListByBuyerIdAndIndexAndPageSize(buyerSession.getBuyerId(), index, onePageSize);
        countTemp = orderReturnDAO.getTotalCountByBuyerId(buyerSession.getBuyerId());

        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        List<ComplexOrderReturn> complexOrderReturnListTemp = new ArrayList<ComplexOrderReturn>();
        for (OrderReturn orT : resList)
        {
            ComplexOrderReturn corTemp = new ComplexOrderReturn();
            corTemp.setOrderReturn(orT);
            Order orderTTT = orderDAO.findById(orT.getOrderId());
            corTemp.setOrder(orderTTT);

            List<GoodsHistoryItem> goodsHistoryItemList = new ArrayList<GoodsHistoryItem>();
            List<OrderGoods> orderGoodsList = orderGoodsDAO.findByProperty(OrderGoodsDAO.ORDER_ID, orderTTT.getOrderId());
            for (OrderGoods orderGoods : orderGoodsList)
            {
                GoodsHistoryItem goodsHistoryItem = new GoodsHistoryItem();
                GoodsHistory goodsHistoryTemp = goodsHistoryDAO.findByGoodsIdAndGoodsUpdateTime(orderGoods.getGoodsId(), orderGoods.getGoodsUpdateTime());
                goodsHistoryItem.setGoodsHistory(goodsHistoryTemp);
                goodsHistoryItem.setNumber(orderGoods.getGoodsNumber());
                goodsHistoryItem.setCommentId(orderGoods.getCommentId());
                goodsHistoryItemList.add(goodsHistoryItem);
            }
            corTemp.setGoodsHistoryItemList(goodsHistoryItemList);

            complexOrderReturnListTemp.add(corTemp);
        }

        setComplexOrderReturnList(complexOrderReturnListTemp);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_could_apply_return_order_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        int onePageSize = 20;
        List<Order> resList = null;
        int countTemp = 0;

        resList = orderDAO.getListByBuyerIdAndIndexAndPageSizeAndStatus(buyerSession.getBuyerId(), index, onePageSize, IStatus.ORDER_TO_BE_COMMENTED);
        countTemp = orderDAO.getTotalCountByBuyerIdAndStatus(buyerSession.getBuyerId(), IStatus.ORDER_TO_BE_COMMENTED);
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        List<ComplexOrder> complexOrderListTemp = new ArrayList<ComplexOrder>();
        for (Order orderTTT : resList)
        {
            ComplexOrder complexOrderTemp = new ComplexOrder();
            complexOrderTemp.setOrder(orderTTT);

            List<GoodsHistoryItem> goodsHistoryItemList = new ArrayList<GoodsHistoryItem>();
            List<OrderGoods> orderGoodsList = orderGoodsDAO.findByProperty(OrderGoodsDAO.ORDER_ID, orderTTT.getOrderId());
            for (OrderGoods orderGoods : orderGoodsList)
            {
                GoodsHistoryItem goodsHistoryItem = new GoodsHistoryItem();
                GoodsHistory goodsHistoryTemp = goodsHistoryDAO.findByGoodsIdAndGoodsUpdateTime(orderGoods.getGoodsId(), orderGoods.getGoodsUpdateTime());
                goodsHistoryItem.setGoodsHistory(goodsHistoryTemp);
                goodsHistoryItem.setNumber(orderGoods.getGoodsNumber());
                goodsHistoryItem.setCommentId(orderGoods.getCommentId());
                goodsHistoryItemList.add(goodsHistoryItem);
            }
            complexOrderTemp.setGoodsHistoryItemList(goodsHistoryItemList);

            complexOrderListTemp.add(complexOrderTemp);
        }

        setComplexOrderList(complexOrderListTemp);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_collection_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        int onePageSize = 20;
        List<BuyerCollection> resList = null;
        int countTemp = 0;

        resList = buyerCollectionDAO.getListByBuyerIdAndCollectionTypeIndexAndPageSize(buyerSession.getBuyerId(), IStatus.COLLECTION_TYPE_GOODS, index, onePageSize);
        countTemp = buyerCollectionDAO.getTotalCountByBuyerIdAndCollectionType(buyerSession.getBuyerId(), IStatus.COLLECTION_TYPE_GOODS);
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        List<CollectionView> collectionViewListTemp = new ArrayList<CollectionView>();
        for (BuyerCollection bcTTT : resList)
        {

            CollectionView collectionViewTemp = new CollectionView();
            collectionViewTemp.setBuyerCollection(bcTTT);

            Goods goodsFromDB = goodsDAO.findById(bcTTT.getPrimaryId());
            collectionViewTemp.setCollectionObject(goodsFromDB);
            collectionViewListTemp.add(collectionViewTemp);
        }

        setCollectionViewList(collectionViewListTemp);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_browser_history_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        int onePageSize = 20;
        List<BrowserHistory> resList = null;
        int countTemp = 0;

        resList = browserHistoryDAO.getListByBuyerIdAndIndexAndPageSize(buyerSession.getBuyerId(), index, onePageSize);
        countTemp = browserHistoryDAO.getTotalCountByBuyerId(buyerSession.getBuyerId());
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        List<BrowserHistoryView> browserHistoryViewListTemp = new ArrayList<BrowserHistoryView>();
        for (BrowserHistory bhTTT : resList)
        {

            BrowserHistoryView browserHistoryViewTemp = new BrowserHistoryView();
            browserHistoryViewTemp.setBrowserHistory(bhTTT);

            Goods goodsFromDB = goodsDAO.findById(bhTTT.getGoodsId());
            browserHistoryViewTemp.setGoods(goodsFromDB);
            browserHistoryViewListTemp.add(browserHistoryViewTemp);
        }

        setBrowserHistoryViewList(browserHistoryViewListTemp);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_buyer_comment_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        int onePageSize = 20;
        List<Comment> resList = null;
        int countTemp = 0;

        resList = commentDAO.getListByBuyerIdAndIndexAndPageSize(buyerSession.getBuyerId(), index, onePageSize);
        countTemp = commentDAO.getTotalCountByBuyerId(buyerSession.getBuyerId());
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        List<CommentView> commentViewListTemp = new ArrayList<CommentView>();
        for (Comment commentT : resList)
        {
            CommentView commentViewTemp = new CommentView();
            commentViewTemp.setComment(commentT);

            Goods goodsFromDB = goodsDAO.findById(commentT.getGoodsId());
            commentViewTemp.setGoods(goodsFromDB);

            commentViewListTemp.add(commentViewTemp);
        }

        setCommentViewList(commentViewListTemp);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_goods_comment_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        String id_pass = getRequest().getParameter("id");
        if (CM.validIsEmpty(id_pass))
        {
            return GLOBAL_RESULT_404;
        }

        int onePageSize = 20;
        List<Comment> resList = null;
        int countTemp = 0;

        resList = commentDAO.getListByGoodsIdAndIndexAndPageSize(id_pass, index, onePageSize);
        countTemp = commentDAO.getTotalCountByGoodsId(id_pass);
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        setCommentList(resList);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_goods_message_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        String id_pass = getRequest().getParameter("id");
        if (CM.validIsEmpty(id_pass))
        {
            return GLOBAL_RESULT_404;
        }

        int onePageSize = 20;
        List<BuyerMessage> resList = null;
        int countTemp = 0;

        resList = buyerMessageDAO.getListByGoodsIdAndStatusAndIndexAndPageSize(id_pass, IStatus.BUYER_MESSAGE_STATUS_HAVE_REPLYED, index, onePageSize);
        countTemp = buyerMessageDAO.getTotalCountByGoodsIdAndStatus(id_pass, IStatus.BUYER_MESSAGE_STATUS_HAVE_REPLYED);
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        setBuyerMessageList(resList);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_buyer_address_list()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        List<BuyerAddress> buyerAddressListTemp = buyerAddressDAO.findByBuyerId(buyerSession.getBuyerId());
        setBuyerAddressList(buyerAddressListTemp);
        return SUCCESS;
    }

    public String get_buyer_ajax_address_list()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        List<BuyerAddress> buyerAddressListTemp = buyerAddressDAO.findByBuyerId(buyerSession.getBuyerId());
        setBuyerAddressList(buyerAddressListTemp);
        return SUCCESS;
    }

    public String u_add_new_address_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getBuyerAddress() == null)
        {
            info = "输入地址不能为空。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        int address_current_total_count = buyerAddressDAO.getTotalCountByBuyerId(buyerSession.getBuyerId());
        if (address_current_total_count >= 10)
        {
            info = "收货地址最多可以存储10个。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        List<String> needValidNullStrList = new ArrayList<String>();
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressName());
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressPhone());
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressDetail());
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressProvince());
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressCity());
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressDistrict());
        if (CM.validAtLeastOneIsEmpty(needValidNullStrList))
        {
            info = "所有输入都是必填项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        getBuyerAddress().setBuyerAddressId(CM.getRandomTwentyFivePrimaryKeyId());
        Timestamp addTime = new Timestamp(Calendar.getInstance().getTimeInMillis());
        getBuyerAddress().setBuyerAddressAddTime(addTime);
        getBuyerAddress().setBuyerAddressUpdateTime(addTime);

        getBuyerAddress().setBuyerId(buyerSession.getBuyerId());
        String addressDefault = getRequest().getParameter("addressDefault");
        if (addressDefault.equals("true"))
        {
            getBuyerAddress().setBuyerAddressDefault("1");
        }
        else
        {
            getBuyerAddress().setBuyerAddressDefault("0");
        }

        BuyerAddress buyerAddressResult = buyerAddressDAO.save_buyerAddress_with_default_address(getBuyerAddress());
        if (buyerAddressResult == null)
        {
            info = "添加新地址失败，请检查之后重新添加。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        json.put("address", buyerAddressResult);
        json.put("success", true);
        return SUCCESS;
    }

    public String u_update_address_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getBuyerAddress() == null)
        {
            info = "输入地址不能为空。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        List<String> needValidNullStrList = new ArrayList<String>();
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressId());
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressName());
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressPhone());
        needValidNullStrList.add(getBuyerAddress().getBuyerAddressDetail());
        if (CM.validAtLeastOneIsEmpty(needValidNullStrList))
        {
            info = "所有输入都是必填项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        BuyerAddress buyerAddressFromDB = buyerAddressDAO.findById(getBuyerAddress().getBuyerAddressId());
        if (buyerAddressFromDB == null)
        {
            info = "没有找到正在修改的收货地址。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        buyerAddressFromDB.setBuyerAddressName(getBuyerAddress().getBuyerAddressName());
        buyerAddressFromDB.setBuyerAddressDetail(getBuyerAddress().getBuyerAddressDetail());
        buyerAddressFromDB.setBuyerAddressPhone(getBuyerAddress().getBuyerAddressPhone());
        buyerAddressFromDB.setBuyerAddressUpdateTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));

        String addressDefault = getRequest().getParameter("addressDefault");
        if (addressDefault.equals("true"))
        {
            buyerAddressFromDB.setBuyerAddressDefault("1");
        }
        else
        {
            buyerAddressFromDB.setBuyerAddressDefault("0");
        }

        BuyerAddress buyerAddressResult = buyerAddressDAO.save_buyerAddress_with_default_address(buyerAddressFromDB);
        if (buyerAddressResult == null)
        {
            info = "修改地址失败，请检查之后重新操作。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        json.put("success", true);
        return SUCCESS;
    }

    public String u_delete_address_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getBuyerAddress() == null || CM.validIsEmptyWithTrim(getBuyerAddress().getBuyerAddressId()))
        {
            info = "输入地址不能为空。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        BuyerAddress buyerAddressFromDB = buyerAddressDAO.findById(getBuyerAddress().getBuyerAddressId());
        if (buyerAddressFromDB == null)
        {
            info = "没有找到正在删除的收货地址。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        int del_res = buyerAddressDAO.delete(buyerAddressFromDB);
        if (del_res != IResult.DELETE_SUCCESS)
        {
            info = "删除地址失败，请检查之后重新操作。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        json.put("success", true);
        return SUCCESS;
    }

    public String show_order_detail()
    {
        String id_pass = getRequest().getParameter("id");
        if (CM.validIsEmpty(id_pass))
        {
            return GLOBAL_RESULT_404;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        Order orderResult = orderDAO.findByIdAndBuyerId(id_pass, buyerSession.getBuyerId());
        if (orderResult == null)
        {
            return GLOBAL_RESULT_404;
        }

        ComplexOrder complexOrderTemp = new ComplexOrder();
        complexOrderTemp.setOrder(orderResult);

        List<GoodsHistoryItem> goodsHistoryItemList = new ArrayList<GoodsHistoryItem>();
        List<OrderGoods> orderGoodsList = orderGoodsDAO.findByProperty(OrderGoodsDAO.ORDER_ID, orderResult.getOrderId());
        for (OrderGoods orderGoods : orderGoodsList)
        {
            GoodsHistoryItem goodsHistoryItem = new GoodsHistoryItem();
            GoodsHistory goodsHistoryTemp = goodsHistoryDAO.findByGoodsIdAndGoodsUpdateTime(orderGoods.getGoodsId(), orderGoods.getGoodsUpdateTime());
            goodsHistoryItem.setGoodsHistory(goodsHistoryTemp);
            goodsHistoryItem.setNumber(orderGoods.getGoodsNumber());
            goodsHistoryItem.setCommentId(orderGoods.getCommentId());
            goodsHistoryItemList.add(goodsHistoryItem);
        }
        complexOrderTemp.setGoodsHistoryItemList(goodsHistoryItemList);

        setComplexOrder(complexOrderTemp);
        return SUCCESS;
    }

    public String get_home_data()
    {
        List<GoodsType> goodsTypeListTemp = goodsTypeDAO.findAll();
        if (goodsTypeListTemp.size() == 0)
        {
            setGoodsTypeJson(null);
        }
        Map<String, GoodsTypeView> goodsTypeMap = new LinkedHashMap<String, GoodsTypeView>();
        for (GoodsType gt : goodsTypeListTemp)
        {
            GoodsTypeView gtvTemp = new GoodsTypeView();
            gtvTemp.setId(gt.getGoodsTypeId());
            gtvTemp.setName(gt.getGoodsTypeName());
            gtvTemp.setpId(gt.getGoodsTypeParentId() == null ? "" : gt.getGoodsTypeParentId());
            gtvTemp.setOpen(true);
            gtvTemp.setNoR(false);
            gtvTemp.setGrade(1);
            goodsTypeMap.put(gt.getGoodsTypeId(), gtvTemp);
        }
        List<GoodsTypeView> goodsTypeViewListForJson = new ArrayList<GoodsTypeView>();
        Set<Map.Entry<String, GoodsTypeView>> set = goodsTypeMap.entrySet();
        for (Iterator<Map.Entry<String, GoodsTypeView>> it = set.iterator(); it.hasNext(); )
        {
            Map.Entry<String, GoodsTypeView> entry = (Map.Entry<String, GoodsTypeView>) it.next();
            // System.out.println(entry.getKey() + "--->" + entry.getValue());
            if (CM.validIsEmpty(entry.getValue().getpId()))
            {
                entry.getValue().setGrade(1);
                goodsTypeMap.put(entry.getKey(), entry.getValue());
            }
            else if (CM.validIsEmpty(goodsTypeMap.get(entry.getValue().getpId()).getpId()))
            {
                entry.getValue().setGrade(2);
                goodsTypeMap.put(entry.getKey(), entry.getValue());
            }
            else if (CM.validIsEmpty(goodsTypeMap.get(goodsTypeMap.get(entry.getValue().getpId()).getpId()).getpId()))
            {
                entry.getValue().setGrade(3);
                goodsTypeMap.put(entry.getKey(), entry.getValue());
            }
            goodsTypeViewListForJson.add(entry.getValue());
        }

        List<GoodsTypeViewAndList> goodsTypeViewAndListForShowList = new ArrayList<GoodsTypeViewAndList>();
        for (int i = 0; i < goodsTypeViewListForJson.size(); i++)
        {
            if (goodsTypeViewListForJson.get(i).getGrade() == 1)
            {
                GoodsTypeViewAndList goodsTypeViewAndListTemp = new GoodsTypeViewAndList();
                goodsTypeViewAndListTemp.setView(goodsTypeViewListForJson.get(i));
                goodsTypeViewAndListForShowList.add(goodsTypeViewAndListTemp);
            }
        }
        for (int i = 0; i < goodsTypeViewAndListForShowList.size(); i++)
        {
            List<GoodsTypeViewAndList> goodsTypeViewAndListForShowList_2 = new ArrayList<GoodsTypeViewAndList>();
            for (int j = 0; j < goodsTypeViewListForJson.size(); j++)
            {
                if (goodsTypeViewListForJson.get(j).getGrade() == 2 && goodsTypeViewListForJson.get(j).getpId().equals(goodsTypeViewAndListForShowList.get(i).getView().getId()))
                {
                    GoodsTypeViewAndList goodsTypeViewAndListTemp = new GoodsTypeViewAndList();
                    goodsTypeViewAndListTemp.setView(goodsTypeViewListForJson.get(j));
                    goodsTypeViewAndListForShowList_2.add(goodsTypeViewAndListTemp);
                }
            }
            goodsTypeViewAndListForShowList.get(i).setList(goodsTypeViewAndListForShowList_2);
        }
        for (int i = 0; i < goodsTypeViewAndListForShowList.size(); i++)
        {
            String i_Str = "";
            for (int j = 0; j < goodsTypeViewAndListForShowList.get(i).getList().size(); j++)
            {
                String j_Str = "";
                List<GoodsTypeViewAndList> goodsTypeViewAndListForShowList_3 = new ArrayList<GoodsTypeViewAndList>();
                for (int k = 0; k < goodsTypeViewListForJson.size(); k++)
                {
                    if (goodsTypeViewListForJson.get(k).getGrade() == 3 && goodsTypeViewListForJson.get(k).getpId().equals(goodsTypeViewAndListForShowList.get(i).getList().get(j).getView().getId()))
                    {
                        GoodsTypeViewAndList goodsTypeViewAndListTemp = new GoodsTypeViewAndList();
                        goodsTypeViewAndListTemp.setView(goodsTypeViewListForJson.get(k));
                        goodsTypeViewAndListTemp.getView().setChildrenIds(goodsTypeViewAndListTemp.getView().getId());
                        goodsTypeViewAndListForShowList_3.add(goodsTypeViewAndListTemp);
                        // 记录下一级id
                        j_Str += goodsTypeViewListForJson.get(k).getId() + ",";
                    }
                }
                j_Str = goodsTypeViewAndListForShowList.get(i).getList().get(j).getView().getId() + "," + j_Str;
                if (j_Str.length() > 0)
                {
                    i_Str += j_Str;
                }
                // 设置此级别孩子id
                goodsTypeViewAndListForShowList.get(i).getList().get(j).getView().setChildrenIds(j_Str.length() > 0 ? j_Str.substring(0, j_Str.length() - 1) : "");
                goodsTypeViewAndListForShowList.get(i).getList().get(j).setList(goodsTypeViewAndListForShowList_3);
            }
            i_Str = goodsTypeViewAndListForShowList.get(i).getView().getId() + "," + i_Str;
            // 设置此级别孩子id
            goodsTypeViewAndListForShowList.get(i).getView().setChildrenIds(i_Str.length() > 0 ? i_Str.substring(0, i_Str.length() - 1) : "");
        }

        setViewAndList(goodsTypeViewAndListForShowList);

        Map<String, List<Goods>> goodsTypeAndGoodsListMapTemp = new HashMap<String, List<Goods>>();

        for (GoodsTypeViewAndList gtvl : goodsTypeViewAndListForShowList)
        {
            // System.out.println(gtvl.getView().getId() + "," +
            // gtvl.getView().getName() + "," +
            // gtvl.getView().getChildrenIds());
            for (GoodsTypeViewAndList gtvl2 : gtvl.getList())
            {
                // System.out.println("----" + gtvl2.getView().getId() + "," +
                // gtvl2.getView().getName() + "," +
                // gtvl2.getView().getChildrenIds());
                List<Goods> goodsListFromDB = goodsDAO.getListByIndexAndPageSizeAndStatusAndTypeIdListAndOrderBy(1, 4, IStatus.GOODS_IS_ON_SALE, CM.fromSomePictureSrcToOneList(gtvl2.getView().getChildrenIds()), "goodsUpdateTime");
                goodsTypeAndGoodsListMapTemp.put(gtvl2.getView().getId(), goodsListFromDB);
            }
        }

        setGoodsTypeAndGoodsListMap(goodsTypeAndGoodsListMapTemp);

        setM_h1_advertisementList(advertisementDAO.getListByIndexAndPageSizeAnd_type_userId(1, 10, IStatus.ADVERTISEMENT_M_H1, null));

        setM_h2_advertisementList(advertisementDAO.getListByIndexAndPageSizeAnd_type_userId(1, 10, IStatus.ADVERTISEMENT_M_H2, null));
        return SUCCESS;
    }

    public String u_cancel_order_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getCommonStr() == null || CM.validIsEmpty(getCommonStr()))
        {
            info = "订单id是必需项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        List<Order> orderListTemp = orderDAO.findByIdsAndBuyerId(CM.fromSomePictureSrcToOneList(getCommonStr()), buyerSession.getBuyerId());
        if (orderListTemp == null || orderListTemp.size() == 0)
        {
            info = "没有找到这些订单。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        List<Goods> goodsList = new ArrayList<Goods>();
        for (Order ordTemp : orderListTemp)
        {
            if (ordTemp.getOrderStatus().equals(IStatus.ORDER_TO_BE_PAYED))
            {
                ordTemp.setOrderStatus(IStatus.ORDER_HAVE_BEEN_CANCELLED);

                List<OrderGoods> orderGoodsList = orderGoodsDAO.findByOrderId(ordTemp.getOrderId());
                for (OrderGoods orderGoodsTemp : orderGoodsList)
                {
                    Goods goodsTemp = goodsDAO.findById(orderGoodsTemp.getGoodsId());
                    goodsTemp.setGoodsInventoryNumber(goodsTemp.getGoodsInventoryNumber() + orderGoodsTemp.getGoodsNumber());
                    goodsList.add(goodsTemp);
                }
            }
        }

        List<Order> orderListResult = orderDAO.batchCancelOrder(orderListTemp, goodsList);
        if (orderListResult == null || orderListResult.size() == 0)
        {
            info = "操作失败。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        json.put("success", true);
        return SUCCESS;
    }

    public String u_valid_goods_collection()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        String id_pass = getRequest().getParameter("id");
        if (CM.validIsEmpty(id_pass))
        {
            info = "参数有误。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        BuyerCollection buyerCollectionFromDB = buyerCollectionDAO.findByBuyerIdAndPrimaryIdAndCollectionType(buyerSession.getBuyerId(), id_pass, IStatus.COLLECTION_TYPE_GOODS);
        if (buyerCollectionFromDB == null)
        {
            json.put("success", true);
            json.put("isCollected", false);
            return SUCCESS;
        }
        else
        {
            json.put("success", true);
            json.put("isCollected", true);
            json.put("collectionId", buyerCollectionFromDB.getCollectionId());
            return SUCCESS;
        }
    }

    public String u_add_goods_collection_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getBuyerCollection() == null || CM.validIsEmpty(getBuyerCollection().getPrimaryId()) || CM.validIsEmpty(getBuyerCollection().getCollectionType()))
        {
            info = "参数有误。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        BuyerCollection buyerCollectionFromDB = buyerCollectionDAO.findByBuyerIdAndPrimaryIdAndCollectionType(buyerSession.getBuyerId(), getBuyerCollection().getPrimaryId(), getBuyerCollection().getCollectionType());
        if (buyerCollectionFromDB == null)
        {
            getBuyerCollection().setCollectionId(CM.getRandomTwentyFivePrimaryKeyId());
            getBuyerCollection().setBuyerId(buyerSession.getBuyerId());
            getBuyerCollection().setCollectionTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
            BuyerCollection buyerCollectionResult = buyerCollectionDAO.save(getBuyerCollection());
            if (buyerCollectionResult == null)
            {
                info = "收藏失败，请稍后重试。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }

            json.put("success", true);
            json.put("collectionId", buyerCollectionResult.getCollectionId());
            return SUCCESS;
        }

        json.put("success", true);
        json.put("collectionId", buyerCollectionFromDB.getCollectionId());
        return SUCCESS;
    }

    public String u_cancel_goods_collection_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getBuyerCollection() == null || CM.validIsEmpty(getBuyerCollection().getCollectionId()))
        {
            info = "参数有误。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        BuyerCollection buyerCollectionFromDB = buyerCollectionDAO.findByCollectionIdAndBuyerId(getBuyerCollection().getCollectionId(), buyerSession.getBuyerId());
        if (buyerCollectionFromDB == null)
        {
            info = "没有此收藏或你已经取消收藏。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        int delResult = buyerCollectionDAO.delete(buyerCollectionFromDB);
        if (delResult != IResult.DELETE_SUCCESS)
        {
            info = "取消收藏时出现错误，请稍后重试。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        json.put("success", true);
        return SUCCESS;
    }

    public String u_add_browser_history_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        if (getBrowserHistory() == null || CM.validIsEmpty(getBrowserHistory().getGoodsId()))
        {
            info = "参数有误。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        BrowserHistory browserHistoryFromDB = browserHistoryDAO.findByGoodsIdAndBuyerId(getBrowserHistory().getGoodsId(), buyerSession.getBuyerId());
        if (browserHistoryFromDB == null)
        {
            getBrowserHistory().setBrowserHistoryId(CM.getRandomTwentyFivePrimaryKeyId());
            getBrowserHistory().setBuyerId(buyerSession.getBuyerId());
            getBrowserHistory().setBrowserTimes(1);
            getBrowserHistory().setBrowserHistoryTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));

            BrowserHistory browserHistoryResult = browserHistoryDAO.save(getBrowserHistory());
            if (browserHistoryResult == null)
            {
                info = "添加浏览记录失败，请稍后重试。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }
        }
        else
        {
            int current_times = browserHistoryFromDB.getBrowserTimes().intValue();
            browserHistoryFromDB.setBrowserTimes(current_times + 1);
            browserHistoryFromDB.setBrowserHistoryTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
            BrowserHistory browserHistoryResult = browserHistoryDAO.save(browserHistoryFromDB);
            if (browserHistoryResult == null)
            {
                info = "添加浏览记录失败，请稍后重试。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }
        }

        json.put("success", true);
        return SUCCESS;
    }

    public void receive_notify_url_do() throws IOException
    {

        getRequest().setCharacterEncoding("UTF-8");
        getResponse().setContentType("text/plain");
        getResponse().setCharacterEncoding("UTF-8");
        PrintWriter out = getResponse().getWriter();

        // 获取请求数据
        MchPayNotify payNotify = XMLConverUtil.convertToObject(MchPayNotify.class, getRequest().getInputStream());
        // 已处理 去重
        if (expireSet.contains(payNotify.getTransaction_id()))
        {
            return;
        }

        // 签名验证
        if (SignatureUtil.validateAppSignature(payNotify, GlobalConfig.API_KEY))
        {
            String id_pass = payNotify.getOut_trade_no();

            if (CM.validIsEmptyWithTrim(id_pass))
            {
                info = "订单号不能为空！";

                MchBaseResult baseResult = new MchBaseResult();
                baseResult.setReturn_code("FAIL");
                baseResult.setReturn_msg(info);
                getResponse().getOutputStream().write(XMLConverUtil.convertToXML(baseResult).getBytes());
                return;
            }

            Order orderRes = orderDAO.findById(id_pass);
            if (orderRes == null)
            {
                info = "没有找到您要付款的订单！";
                MchBaseResult baseResult = new MchBaseResult();
                baseResult.setReturn_code("FAIL");
                baseResult.setReturn_msg(info);
                getResponse().getOutputStream().write(XMLConverUtil.convertToXML(baseResult).getBytes());
                return;
            }

            if (!orderRes.getOrderStatus().equals(IStatus.ORDER_TO_BE_PAYED))
            {
                info = "此订单可能已经支付过！只有待付款的订单才能支付。";
                MchBaseResult baseResult = new MchBaseResult();
                baseResult.setReturn_code("FAIL");
                baseResult.setReturn_msg(info);
                getResponse().getOutputStream().write(XMLConverUtil.convertToXML(baseResult).getBytes());
                return;
            }

            orderRes.setOrderPayWay(IStatus.PAY_STYLE_WECHAT_PAY);
            orderRes.setOrderOnlineTradeNo(payNotify.getTransaction_id());
            orderRes.setOrderReceiveWay(IStatus.RECEIVE_STYLE_DELIVER_DOOR);
            orderRes.setOrderStatus(IStatus.ORDER_TO_BE_SEND);
            orderRes.setOrderPayTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));

            Order updOrderRes = orderDAO.save(orderRes);
            if (updOrderRes == null)
            {
                info = "处理订单失败！";
                MchBaseResult baseResult = new MchBaseResult();
                baseResult.setReturn_code("FAIL");
                baseResult.setReturn_msg(info);
                getResponse().getOutputStream().write(XMLConverUtil.convertToXML(baseResult).getBytes());
                return;
            }

            // 给用户发送支付成功通知
            Buyer buyerFromDB = buyerDAO.findById(updOrderRes.getBuyerId());
            if (buyerFromDB != null)
            {
                CP.push_pay_money_success(buyerFromDB.getBuyerWechat(), updOrderRes);
            }

            // 给上线发送佣金信息
            CP.push_order_completed_commission_info(buyerFromDB, updOrderRes);

            // 将这条记录添加到订单备案表中
            OrderDeclaration orderDeclarationFromDB = orderDeclarationDAO.findByOrderId(updOrderRes.getOrderId());
            if (orderDeclarationFromDB == null)
            {
                orderDeclarationFromDB = new OrderDeclaration();
                orderDeclarationFromDB.setDeclarationId(CM.getRandomTwentyFivePrimaryKeyId());
                orderDeclarationFromDB.setOrderId(updOrderRes.getOrderId());
                orderDeclarationFromDB.setTenpayStatus(IStatus.ORDER_DECLARATION_STATUS_TO_BE_EXECUTED);
                orderDeclarationFromDB.setHaiguanStatus(IStatus.ORDER_DECLARATION_STATUS_TO_BE_EXECUTED);
                orderDeclarationFromDB.setZhijianStatus(IStatus.ORDER_DECLARATION_STATUS_TO_BE_EXECUTED);
                orderDeclarationFromDB.setZhuozhiStatus(IStatus.ORDER_DECLARATION_STATUS_TO_BE_EXECUTED);
            }

            OrderDeclaration orderDeclarationResult = orderDeclarationDAO.save(orderDeclarationFromDB);
            if (orderDeclarationResult != null)
            {
                // 执行财付通申请代码
                ODAPI.do_tenpay_send(updOrderRes.getOrderId());
            }

            // 返回成功消息给微信
            expireSet.add(payNotify.getTransaction_id());
            MchBaseResult baseResult = new MchBaseResult();
            baseResult.setReturn_code("SUCCESS");
            baseResult.setReturn_msg("OK");
            getResponse().getOutputStream().write(XMLConverUtil.convertToXML(baseResult).getBytes());
            return;
        }
        else
        {
            MchBaseResult baseResult = new MchBaseResult();
            baseResult.setReturn_code("FAIL");
            baseResult.setReturn_msg("ERROR");
            getResponse().getOutputStream().write(XMLConverUtil.convertToXML(baseResult).getBytes());
            return;
        }

    }

    public String wc_get_user_info() throws IOException
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        String code = getRequest().getParameter("code");

        SnsToken snsToken = SnsAPI.oauth2AccessToken(GlobalConfig.appID, GlobalConfig.appsecret, code);

        if (!CM.validIsEmptyWithTrim(snsToken.getErrcode()))
        {
            info = snsToken.getErrcode() + "获取用户授权失败。";
            System.out.println(info);
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        // 特殊的网页授权access_token
        User user = UserAPI.userInfo(snsToken.getAccess_token(), snsToken.getOpenid());

        System.out.println("当前用户:Access_token:" + snsToken.getAccess_token() + ",OPENID:" + snsToken.getOpenid());

/*		if (!CM.validIsEmptyWithTrim(user.getErrcode()))
		{
			info = user.getErrcode() + "获取用户授权信息失败。";
			System.out.println(info);
			json.put("success", false);
			json.put("info", info);
			return SUCCESS;
		}*/

        Buyer buyerFromDB = buyerDAO.findByBuyerWeChatId(snsToken.getOpenid());
        if (buyerFromDB == null)
        {
            Buyer buyerTemp = new Buyer();
            buyerTemp.setBuyerId(CM.getRandomTwentyFivePrimaryKeyId());
            buyerTemp.setBuyerWechat(snsToken.getOpenid());
            buyerTemp.setBuyerPoints(0);
            buyerTemp.setBuyerStatus(IStatus.BUYER_STATUS_USED);

            if (!CM.validIsEmptyWithTrim(user.getNickname()))
            {
                String nick_name_filter_str = CM.filterEmoji(user.getNickname());
                if (!CM.validIsEmptyWithTrim(nick_name_filter_str))
                {
                    int n_length = nick_name_filter_str.length();
                    buyerTemp.setBuyerNickname(nick_name_filter_str.substring(0, n_length > 50 ? 50 : n_length));
                }
            }
            if (user.getSex() != null)
            {
                buyerTemp.setBuyerSex(String.valueOf(user.getSex()));
            }
            if (!CM.validIsEmptyWithTrim(user.getCity()))
            {
                buyerTemp.setBuyerCity(user.getCity());
            }
            if (!CM.validIsEmptyWithTrim(user.getCountry()))
            {
                buyerTemp.setBuyerCountry(user.getCountry());
            }
            if (!CM.validIsEmptyWithTrim(user.getProvince()))
            {
                buyerTemp.setBuyerProvince(user.getProvince());
            }
            if (!CM.validIsEmptyWithTrim(user.getHeadimgurl()))
            {
                buyerTemp.setBuyerHeadimgurl(user.getHeadimgurl());
            }

            buyerTemp.setBuyerRegisterTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
            Buyer buyerResult = buyerDAO.save(buyerTemp);
            if (buyerResult == null)
            {
                info = "验证用户信息失败。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }

            getSession().setAttribute("buyerSession", buyerResult);
        }
        else
        {
            if (!CM.validIsEmptyWithTrim(user.getNickname()))
            {
                String nick_name_filter_str = CM.filterEmoji(user.getNickname());
                if (!CM.validIsEmptyWithTrim(nick_name_filter_str))
                {
                    int n_length = nick_name_filter_str.length();
                    buyerFromDB.setBuyerNickname(nick_name_filter_str.substring(0, n_length > 50 ? 50 : n_length));
                }
            }
            if (user.getSex() != null)
            {
                buyerFromDB.setBuyerSex(String.valueOf(user.getSex()));
            }
            if (!CM.validIsEmptyWithTrim(user.getCity()))
            {
                buyerFromDB.setBuyerCity(user.getCity());
            }
            if (!CM.validIsEmptyWithTrim(user.getCountry()))
            {
                buyerFromDB.setBuyerCountry(user.getCountry());
            }
            if (!CM.validIsEmptyWithTrim(user.getProvince()))
            {
                buyerFromDB.setBuyerProvince(user.getProvince());
            }
            if (!CM.validIsEmptyWithTrim(user.getHeadimgurl()))
            {
                buyerFromDB.setBuyerHeadimgurl(user.getHeadimgurl());
            }

            Buyer buyerResult = buyerDAO.save(buyerFromDB);
            if (buyerResult == null)
            {
                info = "验证用户信息失败。";
                json.put("success", false);
                json.put("info", info);
                return SUCCESS;
            }

            getSession().setAttribute("buyerSession", buyerResult);
        }

        json.put("success", true);
        json.put("openid", snsToken.getOpenid());
        return SUCCESS;
    }

    public String wc_valid_have_this_person() throws IOException
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        if (buyerSession == null)
        {
            json.put("success", false);
            return SUCCESS;
        }

        json.put("success", true);
        json.put("openid", buyerSession.getBuyerWechat());
        return SUCCESS;
    }

    public String wc_get_wechat_info() throws IOException
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        String currentUrl = getRequest().getParameter("currentUrl");
        Map<String, String> paramMap = CM.sign(TicketManager.getTicket(GlobalConfig.appID), currentUrl);
        json.put("appId", GlobalConfig.appID);
        json.put("timestamp", paramMap.get("timestamp"));
        json.put("nonceStr", paramMap.get("nonceStr"));
        json.put("signature", paramMap.get("signature"));
        json.put("ticket", TicketManager.getTicket(GlobalConfig.appID));
        json.put("currentUrl", currentUrl);

        json.put("success", true);
        return SUCCESS;
    }

    public String show_coupon_detail()
    {
        String actionName = ServletActionContext.getActionMapping().getName();
        Coupon couponTemp = couponDAO.findById(actionName);
        if (couponTemp == null)
        {
            return GLOBAL_RESULT_USER_404;
        }

        setCoupon(couponTemp);
        if (couponTemp.getCouponSnapBeginTime().after(Calendar.getInstance().getTime()))
        {
            getRequest().setAttribute("before", true);
        }
        if (couponTemp.getCouponSnapEndTime().before(Calendar.getInstance().getTime()))
        {
            getRequest().setAttribute("after", true);
        }
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        if (buyerSession != null)
        {
            BuyerCoupon buyerCouponTemp = buyerCouponDAO.findByCouponIdAndBuyerId(couponTemp.getCouponId(), buyerSession.getBuyerId());
            setBuyerCoupon(buyerCouponTemp);
        }
        return SUCCESS;
    }

    public String u_snap_coupon_do() throws IOException
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        String id_pass = getRequest().getParameter("id");
        if (CM.validIsEmpty(id_pass))
        {
            info = "优惠券id是必需项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        Coupon couponTemp = couponDAO.findById(id_pass);
        if (couponTemp == null)
        {
            info = "没有找到此优惠券。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        if (couponTemp.getCouponSnapBeginTime().after(Calendar.getInstance().getTime()))
        {
            info = "还没到抢购优惠券时间。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        if (couponTemp.getCouponSnapEndTime().before(Calendar.getInstance().getTime()))
        {
            info = "已经过了抢购优惠券时间。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        if (couponTemp.getCouponNumber() <= 0)
        {
            info = "已经抢光了。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        BuyerCoupon buyerCouponFromDB = buyerCouponDAO.findByCouponIdAndBuyerId(couponTemp.getCouponId(), buyerSession.getBuyerId());
        if (buyerCouponFromDB != null)
        {
            info = "已经抢过了。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        BuyerCoupon buyerCouponTemp = new BuyerCoupon();
        buyerCouponTemp.setBuyerCouponId(CM.getRandomTwentyFivePrimaryKeyId());
        buyerCouponTemp.setCouponId(couponTemp.getCouponId());
        buyerCouponTemp.setBuyerId(buyerSession.getBuyerId());
        buyerCouponTemp.setBuyerCouponTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
        buyerCouponTemp.setBuyerCouponStatus(IStatus.BUYER_COUPON_STATUS_NOT_USED);

        BuyerCoupon buyerCouponRes = buyerCouponDAO.batch_snap_coupon(couponTemp, buyerCouponTemp);

        json.put("success", true);
        return SUCCESS;
    }

    public String u_get_address_info_do() throws IOException
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        String id_pass = getRequest().getParameter("id");
        if (CM.validIsEmpty(id_pass))
        {
            info = "收货地址id是必需项。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        BuyerAddress buyerAddressFromDB = buyerAddressDAO.findById(id_pass);
        if (buyerAddressFromDB == null)
        {
            info = "没有找到此收货地址。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }

        json.put("address", buyerAddressFromDB);
        json.put("success", true);
        return SUCCESS;
    }

    public String show_buyer_coupon_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        String status = getRequest().getParameter("s");
        int onePageSize = 20;
        List<BuyerCoupon> resList = null;
        int countTemp = 0;

        if (CM.validIsEmpty(status))
        {
            resList = buyerCouponDAO.getListByBuyerIdAndIndexAndPageSize(buyerSession.getBuyerId(), index, onePageSize);
            countTemp = buyerCouponDAO.getTotalCountByBuyerId(buyerSession.getBuyerId());
        }
        else
        {
            resList = buyerCouponDAO.getListByBuyerIdAndCouponStatusAndIndexAndPageSize(buyerSession.getBuyerId(), status, index, onePageSize);
            countTemp = buyerCouponDAO.getTotalCountByBuyerIdAndCouponStatus(buyerSession.getBuyerId(), status);
        }
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        List<BuyerCouponView> buyerCouponViewListTemp = new ArrayList<BuyerCouponView>();
        for (BuyerCoupon bct : resList)
        {
            BuyerCouponView buyerCouponViewTemp = new BuyerCouponView();

            buyerCouponViewTemp.setBuyerCoupon(bct);
            Coupon couponTemp = couponDAO.findById(bct.getCouponId());
            buyerCouponViewTemp.setCoupon(couponTemp);

            buyerCouponViewListTemp.add(buyerCouponViewTemp);
        }

        setBuyerCouponViewList(buyerCouponViewListTemp);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_buyer_message_list()
    {
        // 获取分页
        String iPass = getRequest().getParameter("i");
        int index = 1;
        try
        {
            index = Integer.parseInt(iPass);
        } catch (Exception e)
        {
            index = 1;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        String status = getRequest().getParameter("s");
        int onePageSize = 20;
        List<BuyerMessage> resList = null;
        int countTemp = 0;

        if (CM.validIsEmpty(status))
        {
            resList = buyerMessageDAO.getListByBuyerIdAndIndexAndPageSize(buyerSession.getBuyerId(), index, onePageSize);
            countTemp = buyerMessageDAO.getTotalCountByBuyerId(buyerSession.getBuyerId());
        }
        else
        {
            resList = buyerMessageDAO.getListByBuyerIdAndStatusAndIndexAndPageSize(buyerSession.getBuyerId(), status, index, onePageSize);
            countTemp = buyerMessageDAO.getTotalCountByBuyerIdAndStatus(buyerSession.getBuyerId(), status);
        }
        if (resList == null)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }
        if (countTemp == -1)
        {
            info = "参数有误，暂未查到。";
            return SUCCESS;
        }

        List<BuyerMessageView> buyerMessageViewListTemp = new ArrayList<BuyerMessageView>();
        for (BuyerMessage bmt : resList)
        {
            BuyerMessageView buyerMessageViewTemp = new BuyerMessageView();

            buyerMessageViewTemp.setBuyerMessage(bmt);
            Goods goodsTemp = goodsDAO.findById(bmt.getGoodsId());
            buyerMessageViewTemp.setGoods(goodsTemp);

            buyerMessageViewListTemp.add(buyerMessageViewTemp);
        }

        setBuyerMessageViewList(buyerMessageViewListTemp);
        int ttpTemp = countTemp % onePageSize == 0 ? countTemp / onePageSize : countTemp / onePageSize + 1;
        Page pageTemp = new Page();
        pageTemp.setCurrentIndex(index);
        pageTemp.setTotalPages(ttpTemp);
        setPage(pageTemp);
        return SUCCESS;
    }

    public String show_buyer_qrcode()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        // 如果没有获取过,先获取
        if (buyerSession.getBuyerQrcodeId() == null || buyerSession.getBuyerQrcodeUrl() == null)
        {

            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy");
            SimpleDateFormat sdf2 = new SimpleDateFormat("MM");
            SimpleDateFormat sdf3 = new SimpleDateFormat("dd");
            String path = getRequest().getContextPath();
            String basePath = getRequest().getScheme() + "://" + getRequest().getServerName() + ":" + getRequest().getServerPort() + path + "/";
            String root_path = getRealPath("/");
            String save_folder = "qrcode/" + sdf1.format(calendar.getTime()) + "/" + sdf2.format(calendar.getTime()) + "/" + sdf3.format(calendar.getTime());
            String file_name = CM.getRandomTwentyFivePrimaryKeyId() + ".jpg";

            File folder = new File(root_path + save_folder);
            if (folder.exists() == false)
            {
                folder.mkdirs();
            }

            String access_token = TokenManager.getToken(GlobalConfig.appID);
            int scene_id = CM.getInt32RandomNumber();
            QrcodeTicket qrcodeTicket = QrcodeAPI.qrcodeCreateTemp(access_token, 604800, scene_id);

            BufferedImage image = QrcodeAPI.showqrcode(qrcodeTicket.getTicket());
            File newFile = new File(root_path + save_folder + "/" + file_name);
            try
            {
                ImageIO.write(image, "jpg", newFile);

                BufferedImage big = image;
                BufferedImage small = ImageIO.read(new File(root_path + "file/qrcode_center_logo.jpg"));

                BufferedImage bufImage = new BufferedImage(big.getWidth(), big.getHeight(), BufferedImage.TYPE_INT_RGB);
                Graphics g = bufImage.createGraphics();
                g.drawImage(big, 0, 0, big.getWidth(), big.getHeight(), null);

                int x = (big.getWidth() - small.getWidth()) / 2;
                int y = (big.getHeight() - small.getHeight()) / 2;
                g.drawImage(small, x, y, small.getWidth(), small.getHeight(), null);
                g.dispose();

                int[] sizeArr = {1280, 860, 430, 344, 258};
                for (int i : sizeArr)
                {
                    BufferedImage temp_img = new BufferedImage(i, i, BufferedImage.TYPE_INT_RGB);
                    temp_img.getGraphics().drawImage(bufImage, 0, 0, i, i, null);
                    ImageIO.write(temp_img, "jpg", new File(root_path + save_folder + "/" + file_name.replaceAll(".jpg", "_" + i + ".jpg")));
                }
            } catch (IOException e)
            {
                return SUCCESS;
            }

            buyerSession.setBuyerQrcodeId(scene_id);
            buyerSession.setBuyerQrcodeUrl(basePath + save_folder + "/" + file_name);
            buyerSession.setBuyerQrcodeBeginTime(new Timestamp(calendar.getTimeInMillis()));
            calendar.add(Calendar.DAY_OF_MONTH, 7);
            buyerSession.setBuyerQrcodeEndTime(new Timestamp(calendar.getTimeInMillis()));

            Buyer buyerResult = buyerDAO.save(buyerSession);
            if (buyerResult != null)
            {
                getSession().setAttribute("buyerSession", buyerResult);
            }

        }
        else
        {
            Calendar cal = Calendar.getInstance();
            if (buyerSession.getBuyerQrcodeEndTime() != null)
            {
                cal.setTime(buyerSession.getBuyerQrcodeEndTime());
            }
            else
            {
                cal.setTime(buyerSession.getBuyerQrcodeBeginTime());
                cal.add(Calendar.DAY_OF_MONTH, 7);
            }
            Calendar now = Calendar.getInstance();
            // 如果二维码已经过期的话，重新获取
            if (now.after(cal))
            {
                Calendar calendar = Calendar.getInstance();
                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy");
                SimpleDateFormat sdf2 = new SimpleDateFormat("MM");
                SimpleDateFormat sdf3 = new SimpleDateFormat("dd");
                String path = getRequest().getContextPath();
                String basePath = getRequest().getScheme() + "://" + getRequest().getServerName() + ":" + getRequest().getServerPort() + path + "/";
                String root_path = getRealPath("/");
                String save_folder = "qrcode/" + sdf1.format(calendar.getTime()) + "/" + sdf2.format(calendar.getTime()) + "/" + sdf3.format(calendar.getTime());
                String file_name = CM.getRandomTwentyFivePrimaryKeyId() + ".jpg";

                File folder = new File(root_path + save_folder);
                if (folder.exists() == false)
                {
                    folder.mkdirs();
                }

                String access_token = TokenManager.getToken(GlobalConfig.appID);
                int scene_id = buyerSession.getBuyerQrcodeId();
                QrcodeTicket qrcodeTicket = QrcodeAPI.qrcodeCreateTemp(access_token, 604800, scene_id);

                BufferedImage image = QrcodeAPI.showqrcode(qrcodeTicket.getTicket());
                File newFile = new File(root_path + save_folder + "/" + file_name);
                try
                {
                    ImageIO.write(image, "jpg", newFile);

                    BufferedImage big = image;
                    BufferedImage small = ImageIO.read(new File(root_path + "file/qrcode_center_logo.jpg"));

                    BufferedImage bufImage = new BufferedImage(big.getWidth(), big.getHeight(), BufferedImage.TYPE_INT_RGB);
                    Graphics g = bufImage.createGraphics();
                    g.drawImage(big, 0, 0, big.getWidth(), big.getHeight(), null);

                    int x = (big.getWidth() - small.getWidth()) / 2;
                    int y = (big.getHeight() - small.getHeight()) / 2;
                    g.drawImage(small, x, y, small.getWidth(), small.getHeight(), null);
                    g.dispose();

                    int[] sizeArr = {1280, 860, 430, 344, 258};
                    for (int i : sizeArr)
                    {
                        BufferedImage temp_img = new BufferedImage(i, i, BufferedImage.TYPE_INT_RGB);
                        temp_img.getGraphics().drawImage(bufImage, 0, 0, i, i, null);
                        ImageIO.write(temp_img, "jpg", new File(root_path + save_folder + "/" + file_name.replaceAll(".jpg", "_" + i + ".jpg")));
                    }
                } catch (IOException e)
                {
                    return SUCCESS;
                }

                buyerSession.setBuyerQrcodeUrl(basePath + save_folder + "/" + file_name);
                buyerSession.setBuyerQrcodeBeginTime(new Timestamp(calendar.getTimeInMillis()));
                calendar.add(Calendar.DAY_OF_MONTH, 7);
                buyerSession.setBuyerQrcodeEndTime(new Timestamp(calendar.getTimeInMillis()));

                Buyer buyerResult = buyerDAO.save(buyerSession);
                if (buyerResult != null)
                {
                    getSession().setAttribute("buyerSession", buyerResult);
                }
            }
        }

        return SUCCESS;
    }

    public String show_my_commission()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        Calendar cald = Calendar.getInstance();

        // 查昨天的,所以要减去一天
        cald.add(Calendar.DAY_OF_MONTH, -1);
        cald.set(Calendar.HOUR_OF_DAY, 0);
        cald.set(Calendar.MINUTE, 0);
        cald.set(Calendar.SECOND, 0);
        cald.set(Calendar.MILLISECOND, 0);
        // 开始时间昨天0时0分0秒0毫秒
        Date day_beginTime = cald.getTime();
        cald.set(Calendar.HOUR_OF_DAY, 23);
        cald.set(Calendar.MINUTE, 59);
        cald.set(Calendar.SECOND, 59);
        cald.set(Calendar.MILLISECOND, 999);
        // 结束时间昨天23时59分59秒999毫秒
        Date day_endTime = cald.getTime();

        Calendar cald2 = Calendar.getInstance();
        cald2.set(Calendar.HOUR_OF_DAY, 0);
        cald2.set(Calendar.MINUTE, 0);
        cald2.set(Calendar.SECOND, 0);
        cald2.set(Calendar.MILLISECOND, 0);
        // 当天为本月最后一天
        Date month_endTime = cald2.getTime();
        cald2.set(Calendar.DAY_OF_MONTH, 1);
        // 第一天为本月第一天
        Date month_beginTime = cald2.getTime();

        Calendar cald3 = Calendar.getInstance();

        // 得到本月1号0时0分0秒0毫秒
        cald3.set(Calendar.DAY_OF_MONTH, 1);
        cald3.set(Calendar.HOUR_OF_DAY, 0);
        cald3.set(Calendar.MINUTE, 0);
        cald3.set(Calendar.SECOND, 0);
        cald3.set(Calendar.MILLISECOND, 0);
        // 减去1毫秒,得到上个月最后一天23时59分59秒999毫秒
        cald3.add(Calendar.MILLISECOND, -1);
        cald3.set(Calendar.HOUR_OF_DAY, 0);
        cald3.set(Calendar.MINUTE, 0);
        cald3.set(Calendar.SECOND, 0);
        cald3.set(Calendar.MILLISECOND, 0);
        Date year_endTime = cald3.getTime();

        // 上个月第一天0时0分0秒0毫秒
        cald3.set(Calendar.DAY_OF_MONTH, 1);
        cald3.set(Calendar.HOUR_OF_DAY, 0);
        cald3.set(Calendar.MINUTE, 0);
        cald3.set(Calendar.SECOND, 0);
        cald3.set(Calendar.MILLISECOND, 0);

        // 得到12个月以前第一天0时0分0秒0毫秒
        cald3.set(Calendar.YEAR, -1);
        Date year_beginTime = cald3.getTime();

        CommissionDayRecord commissionDayRecordTemp = commissionDayRecordDAO.findByBuyerIdAndRecordDate(buyerSession.getBuyerId(), day_beginTime);
        setCommissionDayRecord(commissionDayRecordTemp);

        List<CommissionDayRecord> commissionDayRecordListTemp = commissionDayRecordDAO.getListByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(buyerSession.getBuyerId(), 1, 31, month_beginTime, month_endTime);
        setCommissionDayRecordList(commissionDayRecordListTemp);

        List<CommissionMonthRecord> commissionMonthRecordListTemp = commissionMonthRecordDAO.getListByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(buyerSession.getBuyerId(), 1, 12, year_beginTime, year_endTime);
        setCommissionMonthRecordList(commissionMonthRecordListTemp);

        setBuyerList(buyerDAO.getListByIndexAndPageSizeAndBuyerIntroducerAndNotPuTongBuyer(1, 30, buyerSession.getBuyerId()));

        return SUCCESS;
    }

    public String show_my_pre_commission()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        Calendar cald = Calendar.getInstance();

        // 查昨天的,所以要减去一天
        cald.add(Calendar.DAY_OF_MONTH, -1);
        cald.set(Calendar.HOUR_OF_DAY, 0);
        cald.set(Calendar.MINUTE, 0);
        cald.set(Calendar.SECOND, 0);
        cald.set(Calendar.MILLISECOND, 0);
        // 开始时间昨天0时0分0秒0毫秒
        Date day_beginTime = cald.getTime();
        cald.set(Calendar.HOUR_OF_DAY, 23);
        cald.set(Calendar.MINUTE, 59);
        cald.set(Calendar.SECOND, 59);
        cald.set(Calendar.MILLISECOND, 999);
        // 结束时间昨天23时59分59秒999毫秒
        Date day_endTime = cald.getTime();

        Calendar cald2 = Calendar.getInstance();
        cald2.set(Calendar.HOUR_OF_DAY, 0);
        cald2.set(Calendar.MINUTE, 0);
        cald2.set(Calendar.SECOND, 0);
        cald2.set(Calendar.MILLISECOND, 0);
        // 当天为本月最后一天
        Date month_endTime = cald2.getTime();
        cald2.set(Calendar.DAY_OF_MONTH, 1);
        // 第一天为本月第一天
        Date month_beginTime = cald2.getTime();

        Calendar cald3 = Calendar.getInstance();

        // 得到本月1号0时0分0秒0毫秒
        cald3.set(Calendar.DAY_OF_MONTH, 1);
        cald3.set(Calendar.HOUR_OF_DAY, 0);
        cald3.set(Calendar.MINUTE, 0);
        cald3.set(Calendar.SECOND, 0);
        cald3.set(Calendar.MILLISECOND, 0);
        // 减去1毫秒,得到上个月最后一天23时59分59秒999毫秒
        cald3.add(Calendar.MILLISECOND, -1);
        cald3.set(Calendar.HOUR_OF_DAY, 0);
        cald3.set(Calendar.MINUTE, 0);
        cald3.set(Calendar.SECOND, 0);
        cald3.set(Calendar.MILLISECOND, 0);
        Date year_endTime = cald3.getTime();

        // 上个月第一天0时0分0秒0毫秒
        cald3.set(Calendar.DAY_OF_MONTH, 1);
        cald3.set(Calendar.HOUR_OF_DAY, 0);
        cald3.set(Calendar.MINUTE, 0);
        cald3.set(Calendar.SECOND, 0);
        cald3.set(Calendar.MILLISECOND, 0);

        // 得到12个月以前第一天0时0分0秒0毫秒
        cald3.set(Calendar.YEAR, -1);
        Date year_beginTime = cald3.getTime();

        PreCommissionDayRecord preCommissionDayRecordTemp = preCommissionDayRecordDAO.findByBuyerIdAndRecordDate(buyerSession.getBuyerId(), day_beginTime);
        setPreCommissionDayRecord(preCommissionDayRecordTemp);

        List<PreCommissionDayRecord> preCommissionDayRecordListTemp = preCommissionDayRecordDAO.getListByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(buyerSession.getBuyerId(), 1, 31, month_beginTime, month_endTime);
        setPreCommissionDayRecordList(preCommissionDayRecordListTemp);

        List<PreCommissionMonthRecord> preCommissionMonthRecordListTemp = preCommissionMonthRecordDAO.getListByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(buyerSession.getBuyerId(), 1, 12, year_beginTime, year_endTime);
        setPreCommissionMonthRecordList(preCommissionMonthRecordListTemp);

        return SUCCESS;
    }

    public String xia_xian_commission()
    {
        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");
        String xia_xian_id = getRequest().getParameter("id");
        if (CM.validIsEmptyWithTrim(xia_xian_id))
        {
            return GLOBAL_RESULT_USER_404;
        }

        Buyer xia_xian_buyer = buyerDAO.findById(xia_xian_id);
        if (xia_xian_buyer == null || xia_xian_buyer.getBuyerIntroducer().equals(buyerSession.getBuyerId()) == false)
        {
            return GLOBAL_RESULT_USER_404;
        }

        Calendar cald = Calendar.getInstance();

        // 查昨天的,所以要减去一天
        cald.add(Calendar.DAY_OF_MONTH, -1);
        cald.set(Calendar.HOUR_OF_DAY, 0);
        cald.set(Calendar.MINUTE, 0);
        cald.set(Calendar.SECOND, 0);
        cald.set(Calendar.MILLISECOND, 0);
        // 开始时间昨天0时0分0秒0毫秒
        Date day_beginTime = cald.getTime();
        cald.set(Calendar.HOUR_OF_DAY, 23);
        cald.set(Calendar.MINUTE, 59);
        cald.set(Calendar.SECOND, 59);
        cald.set(Calendar.MILLISECOND, 999);
        // 结束时间昨天23时59分59秒999毫秒
        Date day_endTime = cald.getTime();

        Calendar cald2 = Calendar.getInstance();
        cald2.set(Calendar.HOUR_OF_DAY, 0);
        cald2.set(Calendar.MINUTE, 0);
        cald2.set(Calendar.SECOND, 0);
        cald2.set(Calendar.MILLISECOND, 0);
        // 当天为本月最后一天
        Date month_endTime = cald2.getTime();
        cald2.set(Calendar.DAY_OF_MONTH, 1);
        // 第一天为本月第一天
        Date month_beginTime = cald2.getTime();

        Calendar cald3 = Calendar.getInstance();

        // 得到本月1号0时0分0秒0毫秒
        cald3.set(Calendar.DAY_OF_MONTH, 1);
        cald3.set(Calendar.HOUR_OF_DAY, 0);
        cald3.set(Calendar.MINUTE, 0);
        cald3.set(Calendar.SECOND, 0);
        cald3.set(Calendar.MILLISECOND, 0);
        // 减去1毫秒,得到上个月最后一天23时59分59秒999毫秒
        cald3.add(Calendar.MILLISECOND, -1);
        cald3.set(Calendar.HOUR_OF_DAY, 0);
        cald3.set(Calendar.MINUTE, 0);
        cald3.set(Calendar.SECOND, 0);
        cald3.set(Calendar.MILLISECOND, 0);
        Date year_endTime = cald3.getTime();

        // 上个月第一天0时0分0秒0毫秒
        cald3.set(Calendar.DAY_OF_MONTH, 1);
        cald3.set(Calendar.HOUR_OF_DAY, 0);
        cald3.set(Calendar.MINUTE, 0);
        cald3.set(Calendar.SECOND, 0);
        cald3.set(Calendar.MILLISECOND, 0);

        // 得到12个月以前第一天0时0分0秒0毫秒
        cald3.set(Calendar.YEAR, -1);
        Date year_beginTime = cald3.getTime();

        CommissionDayRecord commissionDayRecordTemp = commissionDayRecordDAO.findByBuyerIdAndRecordDate(xia_xian_id, day_beginTime);
        setCommissionDayRecord(commissionDayRecordTemp);

        List<CommissionDayRecord> commissionDayRecordListTemp = commissionDayRecordDAO.getListByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(xia_xian_id, 1, 31, month_beginTime, month_endTime);
        setCommissionDayRecordList(commissionDayRecordListTemp);

        List<CommissionMonthRecord> commissionMonthRecordListTemp = commissionMonthRecordDAO.getListByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(xia_xian_id, 1, 12, year_beginTime, year_endTime);
        setCommissionMonthRecordList(commissionMonthRecordListTemp);

        return SUCCESS;
    }

    public String u_wx_create_customservice_do()
    {
        String method = getRequest().getMethod();
        System.out.println("=========请求是get还是post:" + method);
        if (method.toUpperCase().equals("GET"))
        {
            System.out.println("============如果直接输入网址进来的,什么操作都不做,必须是表单提交的!==========");
            return GLOBAL_RESULT_ILLEGAL_REQUEST;
        }

        Buyer buyerSession = (Buyer) getSession().getAttribute("buyerSession");

        String text = "您好，感谢您对西普茗茶商品的信赖与支持，请您致电我们的人工客服热线020-86535919，由我们的专业客服为您解答。\r\n人工客服工作时间：周一至周五9:30-18:00，敬请您耐心等待，谢谢！";
        TextMessage textMessage = new TextMessage(buyerSession.getBuyerWechat(), text);

        BaseResult baseResult = MessageAPI.messageCustomSend(TokenManager.getToken(GlobalConfig.appID), textMessage);
        if (baseResult == null || baseResult.getErrcode().equals("0") == false)
        {
            info = "操作失败。";
            json.put("success", false);
            json.put("info", info);
            return SUCCESS;
        }
        json.put("success", true);
        return SUCCESS;
    }

    public String show_promotion_list()
    {
        setM_p1_advertisementList(advertisementDAO.getListByIndexAndPageSizeAnd_type_userId(1, 10, IStatus.ADVERTISEMENT_M_P1, null));
        return SUCCESS;
    }

    public void receive_OrderInfoPush_url_do() throws IOException, JSONException
    {

        getRequest().setCharacterEncoding("UTF-8");
        getResponse().setContentType("text/plain");
        getResponse().setCharacterEncoding("UTF-8");
        PrintWriter out = getResponse().getWriter();

        // 获取post参数
        StringBuffer sb = new StringBuffer();
        InputStream is = getRequest().getInputStream();
        InputStreamReader isr = new InputStreamReader(is, "UTF-8");
        BufferedReader br = new BufferedReader(isr);
        String s = "";
        while ((s = br.readLine()) != null)
        {
            sb.append(s);
        }
        String data = URLDecoder.decode(sb.toString(), "utf-8");
        System.out.println("卓志推送订单快递信息:" + data);
        JSONObject paramObject = null;
        if (CM.validIsEmptyWithTrim(data))
        {
            JSONObject declarationObject = new JSONObject();
            declarationObject.put("status", "2");
            declarationObject.put("notes", "没有收到参数");
            out.write(declarationObject.toString());
            out.flush();
            out.close();
            return;
        }
        try
        {
            paramObject = new JSONObject(data);
        } catch (Exception e)
        {
            JSONObject declarationObject = new JSONObject();
            declarationObject.put("status", "2");
            declarationObject.put("notes", "参数格式不正确");
            out.write(declarationObject.toString());
            out.flush();
            out.close();
            return;
        }

        List<String> validList = new ArrayList<String>();
        validList.add(paramObject.getString("enOrderCode"));
        validList.add(paramObject.getString("wayBillNo"));
        validList.add(paramObject.getString("logisticsname"));
        if (CM.validAtLeastOneIsEmpty(validList))
        {
            JSONObject declarationObject = new JSONObject();
            declarationObject.put("status", "2");
            declarationObject.put("notes", "缺少必填项");
            out.write(declarationObject.toString());
            out.flush();
            out.close();
            return;
        }

        Order orderFromDB = orderDAO.findById(paramObject.getString("enOrderCode"));
        if (orderFromDB == null)
        {
            JSONObject declarationObject = new JSONObject();
            declarationObject.put("status", "2");
            declarationObject.put("notes", "没有找到此订单");
            out.write(declarationObject.toString());
            out.flush();
            out.close();
            return;
        }

        List<String> logisticsnameList = new ArrayList<String>();
        logisticsnameList.add("顺丰速运");
        logisticsnameList.add("圆通速递");
        logisticsnameList.add("测试快递");

        String receiveLogisticsName = null;
        for (String str : logisticsnameList)
        {
            if (paramObject.getString("logisticsname").contains(str.substring(0, 2)))
            {
                receiveLogisticsName = str;
                break;
            }
        }

        if (receiveLogisticsName == null)
        {
            JSONObject declarationObject = new JSONObject();
            declarationObject.put("status", "2");
            declarationObject.put("notes", "快递公司编码不对");
            out.write(declarationObject.toString());
            out.flush();
            out.close();
            return;
        }

        if (CM.validIsEmptyWithTrim(orderFromDB.getOrderExpressCompany()) == false)
        {
            JSONObject declarationObject = new JSONObject();
            declarationObject.put("status", "2");
            declarationObject.put("notes", "快递信息已存在");
            out.write(declarationObject.toString());
            out.flush();
            out.close();
            return;
        }

        orderFromDB.setOrderExpressCompany(receiveLogisticsName);
        orderFromDB.setOrderExpressNumber(paramObject.getString("wayBillNo").trim());
        orderFromDB.setOrderStatus(IStatus.ORDER_TO_BE_RECEIVED);
        orderFromDB.setOrderSendTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));

        Order resOrder = orderDAO.save(orderFromDB);
        if (resOrder == null)
        {
            JSONObject declarationObject = new JSONObject();
            declarationObject.put("status", "2");
            declarationObject.put("notes", "保存快递信息失败");
            out.write(declarationObject.toString());
            out.flush();
            out.close();
            return;
        }

        // 给用户发送订单发货通知
        Buyer buyerFromDB = buyerDAO.findById(resOrder.getBuyerId());
        if (buyerFromDB != null)
        {
            CP.push_send_out_order_success(buyerFromDB.getBuyerWechat(), resOrder);
        }

        // 卓志执行成功
        OrderDeclaration orderDeclarationFromDB = orderDeclarationDAO.findByOrderId(resOrder.getOrderId());
        if (orderDeclarationFromDB != null)
        {
            orderDeclarationFromDB.setZhuozhiStatus(IStatus.ORDER_DECLARATION_STATUS_EXECUTE_SUCCESS);
            orderDeclarationFromDB.setZhuozhiEndTime(new Timestamp(Calendar.getInstance().getTimeInMillis()));
            orderDeclarationDAO.save(orderDeclarationFromDB);
        }

        JSONObject declarationObject = new JSONObject();
        declarationObject.put("status", "1");
        out.write(declarationObject.toString());
        out.flush();
        out.close();
        return;

    }

    public Map<String, Object> getJson()
    {
        return json;
    }

    public void setJson(Map<String, Object> json)
    {
        this.json = json;
    }

    public String getGoodsTypeJson()
    {
        return goodsTypeJson;
    }

    public void setGoodsTypeJson(String goodsTypeJson)
    {
        this.goodsTypeJson = goodsTypeJson;
    }

    public Page getPage()
    {
        return page;
    }

    public void setPage(Page page)
    {
        this.page = page;
    }

    public Goods getGoods()
    {
        return goods;
    }

    public void setGoods(Goods goods)
    {
        this.goods = goods;
    }

    public String getCommonStr()
    {
        return commonStr;
    }

    public void setCommonStr(String commonStr)
    {
        this.commonStr = commonStr;
    }

    public Map<String, GoodsType> getGoodsTypeMap()
    {
        return goodsTypeMap;
    }

    public void setGoodsTypeMap(Map<String, GoodsType> goodsTypeMap)
    {
        this.goodsTypeMap = goodsTypeMap;
    }

    public List<Goods> getGoodsList()
    {
        return goodsList;
    }

    public void setGoodsList(List<Goods> goodsList)
    {
        this.goodsList = goodsList;
    }

    public int getRowSize()
    {
        return rowSize;
    }

    public void setRowSize(int rowSize)
    {
        this.rowSize = rowSize;
    }

    public Cart getCart()
    {
        return cart;
    }

    public void setCart(Cart cart)
    {
        this.cart = cart;
    }

    public Map<String, ShopAndGoodsItemList> getCartMap()
    {
        return cartMap;
    }

    public void setCartMap(Map<String, ShopAndGoodsItemList> cartMap)
    {
        this.cartMap = cartMap;
    }

    public boolean isCanSubmitOrder()
    {
        return canSubmitOrder;
    }

    public void setCanSubmitOrder(boolean canSubmitOrder)
    {
        this.canSubmitOrder = canSubmitOrder;
    }

    public String getMessage()
    {
        return message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }

    public BigDecimal getAllTotalPrice()
    {
        return allTotalPrice;
    }

    public void setAllTotalPrice(BigDecimal allTotalPrice)
    {
        this.allTotalPrice = allTotalPrice;
    }

    public BuyerAddress getBuyerAddress()
    {
        return buyerAddress;
    }

    public void setBuyerAddress(BuyerAddress buyerAddress)
    {
        this.buyerAddress = buyerAddress;
    }

    public String getBuyerPeopleId()
    {
        return buyerPeopleId;
    }

    public void setBuyerPeopleId(String buyerPeopleId)
    {
        this.buyerPeopleId = buyerPeopleId;
    }

    public String getBuyerRealName()
    {
        return buyerRealName;
    }

    public void setBuyerRealName(String buyerRealName)
    {
        this.buyerRealName = buyerRealName;
    }

    public List<Order> getOrderList()
    {
        return orderList;
    }

    public void setOrderList(List<Order> orderList)
    {
        this.orderList = orderList;
    }

    public List<ComplexOrder> getComplexOrderList()
    {
        return complexOrderList;
    }

    public void setComplexOrderList(List<ComplexOrder> complexOrderList)
    {
        this.complexOrderList = complexOrderList;
    }

    public List<GoodsTypeViewAndList> getViewAndList()
    {
        return viewAndList;
    }

    public void setViewAndList(List<GoodsTypeViewAndList> viewAndList)
    {
        this.viewAndList = viewAndList;
    }

    public Map<String, List<Goods>> getGoodsTypeAndGoodsListMap()
    {
        return goodsTypeAndGoodsListMap;
    }

    public void setGoodsTypeAndGoodsListMap(Map<String, List<Goods>> goodsTypeAndGoodsListMap)
    {
        this.goodsTypeAndGoodsListMap = goodsTypeAndGoodsListMap;
    }

    public ComplexOrder getComplexOrder()
    {
        return complexOrder;
    }

    public void setComplexOrder(ComplexOrder complexOrder)
    {
        this.complexOrder = complexOrder;
    }

    public boolean isGoodsIsCollected()
    {
        return goodsIsCollected;
    }

    public void setGoodsIsCollected(boolean goodsIsCollected)
    {
        this.goodsIsCollected = goodsIsCollected;
    }

    public BuyerCollection getBuyerCollection()
    {
        return buyerCollection;
    }

    public void setBuyerCollection(BuyerCollection buyerCollection)
    {
        this.buyerCollection = buyerCollection;
    }

    public List<CollectionView> getCollectionViewList()
    {
        return collectionViewList;
    }

    public void setCollectionViewList(List<CollectionView> collectionViewList)
    {
        this.collectionViewList = collectionViewList;
    }

    public BrowserHistory getBrowserHistory()
    {
        return browserHistory;
    }

    public void setBrowserHistory(BrowserHistory browserHistory)
    {
        this.browserHistory = browserHistory;
    }

    public List<BrowserHistoryView> getBrowserHistoryViewList()
    {
        return browserHistoryViewList;
    }

    public void setBrowserHistoryViewList(List<BrowserHistoryView> browserHistoryViewList)
    {
        this.browserHistoryViewList = browserHistoryViewList;
    }

    public Comment getComment()
    {
        return comment;
    }

    public void setComment(Comment comment)
    {
        this.comment = comment;
    }

    public List<CommentView> getCommentViewList()
    {
        return commentViewList;
    }

    public void setCommentViewList(List<CommentView> commentViewList)
    {
        this.commentViewList = commentViewList;
    }

    public List<Comment> getCommentList()
    {
        return commentList;
    }

    public void setCommentList(List<Comment> commentList)
    {
        this.commentList = commentList;
    }

    public Coupon getCoupon()
    {
        return coupon;
    }

    public void setCoupon(Coupon coupon)
    {
        this.coupon = coupon;
    }

    public List<Coupon> getCouponList()
    {
        return couponList;
    }

    public void setCouponList(List<Coupon> couponList)
    {
        this.couponList = couponList;
    }

    public BuyerCoupon getBuyerCoupon()
    {
        return buyerCoupon;
    }

    public void setBuyerCoupon(BuyerCoupon buyerCoupon)
    {
        this.buyerCoupon = buyerCoupon;
    }

    public List<BuyerCouponView> getBuyerCouponViewList()
    {
        return buyerCouponViewList;
    }

    public void setBuyerCouponViewList(List<BuyerCouponView> buyerCouponViewList)
    {
        this.buyerCouponViewList = buyerCouponViewList;
    }

    public List<Article> getArticleList()
    {
        return articleList;
    }

    public void setArticleList(List<Article> articleList)
    {
        this.articleList = articleList;
    }

    public Article getArticle()
    {
        return article;
    }

    public void setArticle(Article article)
    {
        this.article = article;
    }

    public List<BuyerMessage> getBuyerMessageList()
    {
        return buyerMessageList;
    }

    public void setBuyerMessageList(List<BuyerMessage> buyerMessageList)
    {
        this.buyerMessageList = buyerMessageList;
    }

    public BuyerMessage getBuyerMessage()
    {
        return buyerMessage;
    }

    public void setBuyerMessage(BuyerMessage buyerMessage)
    {
        this.buyerMessage = buyerMessage;
    }

    public List<BuyerMessageView> getBuyerMessageViewList()
    {
        return buyerMessageViewList;
    }

    public void setBuyerMessageViewList(List<BuyerMessageView> buyerMessageViewList)
    {
        this.buyerMessageViewList = buyerMessageViewList;
    }

    public List<BuyerAddress> getBuyerAddressList()
    {
        return buyerAddressList;
    }

    public void setBuyerAddressList(List<BuyerAddress> buyerAddressList)
    {
        this.buyerAddressList = buyerAddressList;
    }

    public OrderReturn getOrderReturn()
    {
        return orderReturn;
    }

    public void setOrderReturn(OrderReturn orderReturn)
    {
        this.orderReturn = orderReturn;
    }

    public List<OrderReturn> getOrderReturnList()
    {
        return orderReturnList;
    }

    public void setOrderReturnList(List<OrderReturn> orderReturnList)
    {
        this.orderReturnList = orderReturnList;
    }

    public List<ComplexOrderReturn> getComplexOrderReturnList()
    {
        return complexOrderReturnList;
    }

    public void setComplexOrderReturnList(List<ComplexOrderReturn> complexOrderReturnList)
    {
        this.complexOrderReturnList = complexOrderReturnList;
    }

    public CommissionDayRecord getCommissionDayRecord()
    {
        return commissionDayRecord;
    }

    public void setCommissionDayRecord(CommissionDayRecord commissionDayRecord)
    {
        this.commissionDayRecord = commissionDayRecord;
    }

    public List<CommissionDayRecord> getCommissionDayRecordList()
    {
        return commissionDayRecordList;
    }

    public void setCommissionDayRecordList(List<CommissionDayRecord> commissionDayRecordList)
    {
        this.commissionDayRecordList = commissionDayRecordList;
    }

    public CommissionMonthRecord getCommissionMonthRecord()
    {
        return commissionMonthRecord;
    }

    public void setCommissionMonthRecord(CommissionMonthRecord commissionMonthRecord)
    {
        this.commissionMonthRecord = commissionMonthRecord;
    }

    public List<CommissionMonthRecord> getCommissionMonthRecordList()
    {
        return commissionMonthRecordList;
    }

    public void setCommissionMonthRecordList(List<CommissionMonthRecord> commissionMonthRecordList)
    {
        this.commissionMonthRecordList = commissionMonthRecordList;
    }

    public List<Advertisement> getM_h1_advertisementList()
    {
        return m_h1_advertisementList;
    }

    public void setM_h1_advertisementList(List<Advertisement> m_h1_advertisementList)
    {
        this.m_h1_advertisementList = m_h1_advertisementList;
    }

    public List<Advertisement> getM_h2_advertisementList()
    {
        return m_h2_advertisementList;
    }

    public void setM_h2_advertisementList(List<Advertisement> m_h2_advertisementList)
    {
        this.m_h2_advertisementList = m_h2_advertisementList;
    }

    public List<Advertisement> getM_p1_advertisementList()
    {
        return m_p1_advertisementList;
    }

    public void setM_p1_advertisementList(List<Advertisement> m_p1_advertisementList)
    {
        this.m_p1_advertisementList = m_p1_advertisementList;
    }

    public List<Buyer> getBuyerList()
    {
        return buyerList;
    }

    public void setBuyerList(List<Buyer> buyerList)
    {
        this.buyerList = buyerList;
    }

    public PreCommissionDayRecord getPreCommissionDayRecord()
    {
        return preCommissionDayRecord;
    }

    public void setPreCommissionDayRecord(PreCommissionDayRecord preCommissionDayRecord)
    {
        this.preCommissionDayRecord = preCommissionDayRecord;
    }

    public List<PreCommissionDayRecord> getPreCommissionDayRecordList()
    {
        return preCommissionDayRecordList;
    }

    public void setPreCommissionDayRecordList(List<PreCommissionDayRecord> preCommissionDayRecordList)
    {
        this.preCommissionDayRecordList = preCommissionDayRecordList;
    }

    public PreCommissionMonthRecord getPreCommissionMonthRecord()
    {
        return preCommissionMonthRecord;
    }

    public void setPreCommissionMonthRecord(PreCommissionMonthRecord preCommissionMonthRecord)
    {
        this.preCommissionMonthRecord = preCommissionMonthRecord;
    }

    public List<PreCommissionMonthRecord> getPreCommissionMonthRecordList()
    {
        return preCommissionMonthRecordList;
    }

    public void setPreCommissionMonthRecordList(List<PreCommissionMonthRecord> preCommissionMonthRecordList)
    {
        this.preCommissionMonthRecordList = preCommissionMonthRecordList;
    }

}
